Skip to content

Instantly share code, notes, and snippets.

View try-apim.ps1
#trying out
# start azure cloud shell powershell
New-AzResourceGroup -Name "apim101-rg" -Location "West Europe"
New-AzApiManagement -ResourceGroupName "apim101-rg" -Name "svenmalvik-apim" -Sku "Consumption" -Capacity 0 -Location "West Europe" -Organization "" -AdminEmail ""
# The context tells us what instance of APIM we're working with
$apimCtx = New-AzApiManagementContext -ResourceGroupName "apim101-rg" -ServiceName "svenmalvik-apim"
# Add Conference API to the APIM instance
Import-AzApiManagementApi -Context $apimCtx -SpecificationFormat "Swagger" -SpecificationUrl "" -Path "conf" -ApiId "confapi"
View precreate-git-repos-auth.ps1
$auth = "apitest:j2vsnu3obx55ekwjkfdxfpljziiy27qkuku5jitsx73wvegpdpeq"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($auth)
$token = [System.Convert]::ToBase64String($bytes)
$headers = @{ Authorization = "Basic $token" }
View code-ext.ps1
code --list-extensions
code --install-extension esbenp.prettier-vscode
View activate-pim-role-generic.ps1
# I use SPO Admin a lot, change it to your desired role
$roleToActivate = "SharePoint Administrator"
# default 2 hours, update it to your needs
$hours = 2
$reason = Read-Host "Justify your elevation"
$connection = Connect-AzureAD
$account = $connection.Account
$tenantId = $connection.TenantId
$user = Get-AzureADUser -SearchString $account
$objectId = $user.ObjectId
View add-type-csom-multiple-versions.ps1
$pnpModule = Get-Module PnP.PowerShell -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
View orgassets-global-local.ps1
# This script creates organization assets libraries, organization wide and local ones (country specific)
# Check the status first
Get-SPOTenantCdnEnabled -CdnType Private
Get-SPOTenantCdnOrigins -CdnType Private
# Create a site that will host organization assets
View o365-license-storage.ps1
# it calculates storage capacity in SharePoint Online
# read more on my blog post:
$sku = Get-MsolAccountSku
$sku2 = $sku | % {
$s = $_;
$sr = [PSCustomObject]@{
SkuPartNumber = $s.SkuPartNumber;
Licenses = $s.ActiveUnits + $s.WarningUnits
Services = $s.ServiceStatus | % { $_.ServicePlan.ServiceName };
git config --global ""
git config --global "Azure DevOps"
EXTRAHEADER="Authorization: Bearer $(System.AccessToken)"
git -c http.extraheader="$EXTRAHEADER" clone $REPO
cd $(Build.Repository.Name)
MAINBRANCHNAME=$(git rev-parse --abbrev-ref HEAD)
View demote-news.ps1
$site = "https://{tenant}{site}"
Connect-PnPOnline -Url $site -SPOManagementShell -ClearTokenCache
$field = "Promoted State"
$list = "Site Pages"
$id = 85 #the item id of the news
Set-PnPField -Identity $field -List $list -Values @{ReadOnlyField=$false}
#make sure to enclose the number into quotation marks
Set-PnPListItem -List $list -Identity $id -Values {"Promoted State"="0"}
#reset the field
Set-PnPField -Identity $field -List $list -Values @{ReadOnlyField=$true}
View get-services-health-admin.js
//this little javascript is to get the services to include in the
//Microsoft 365 Admin Center -> Health Center -> Preferences
//Inspect the area in Chrome/Edge and then run this in Console
spans = $0.querySelectorAll('div > div span')
arr2 = => s.innerText).join('\n')