#powershell 20 articles
$host is a constant — and [uri].Host is exactly what you want to store in it gotchas / powershell The obvious name for [uri].Host is reserved and the error blames the value; $input/$args accept the assignment silently and break later Export-Csv -Encoding UTF8 flips the BOM between 5.1 and 7 gotchas / powershell Same parameter, different bytes; Excel reads encoding from the BOM, so the report is readable on one machine and mojibake on the next Get-PnPList -Identity rejects server-relative URLs gotchas / powershell Title/GUID/web-relative only; /sites/team/shared fails as "List does not exist" $ErrorActionPreference = 'Stop' turns a native command's stderr warning into a terminating error gotchas / powershell $ErrorActionPreference='Stop' escalates a benign stderr warning (exit 0) to a script-killer; wrap in 'Continue', judge by $LASTEXITCODE A brand-new Azure subscription blocks your first Function App deployment gotchas / azure-functions New subscriptions start with Y1 quota 0 and unregistered resource providers; the quota is per subscription and per region, so try a neighbouring region first — az appservice list-locations --sku Y1 lists regions you… A generated PowerShell script that embeds file names in a here-string runs code under the admin who runs it gotchas / powershell Data that tenant users can name (file paths, titles) breaks every textual PowerShell literal – expandable here-strings run $(…), ; splits CSV rows, '@ ends a literal here-string; embed data as base64 JSON instead A page-size cap reported as a finding gotchas / rest-api A round number (100 / 500 / 999 / 5000) is the tell; the limit of the request presented as a measurement of the tenant, then cached A syntax check under PowerShell 7 proves nothing about 5.1 gotchas / powershell The parser belongs to the engine hosting it; ternary/??/&& pass in 7 and are parse errors in 5.1, and #Requires never warns you at authoring time ApplicationAccessPolicy won't scope to a shared mailbox — use a mail-enabled security group gotchas / graph "not a security principal"; scope app-only Mail.Send to a mail-enabled security group az CLI can't grant Sites.Selected — the scope is blocked by AADSTS65002 gotchas / graph sites/{id}/permissions needs Sites.FullControl.All; the CLI client can't request it (AADSTS65002), use the Graph PowerShell SDK Azure OpenAI — a pinned model+version in your deploy script is a time bomb gotchas / azure-functions "Deprecating" blocks NEW deployments well before retirement; resolve the newest GA version at deploy time, and match the deployment name to the model family Parentheses in an Azure CLI --query argument break az.cmd on Windows ("-o was unexpected at this time.") gotchas / powershell On Windows az is a batch file; a JMESPath query with ( ) and no spaces reaches cmd unquoted and breaks its IF block – return plain names and count in PowerShell PowerShell 7 [ref] arguments break Office COM calls gotchas / powershell SaveAs2([ref]$x) dies on "psobject to Object"; pass values directly PowerShell 7 treats typographic quotes as string delimiters gotchas / powershell „/" parse like "; localized text in single-quoted here-strings PS 5.1: @(pipeline ConvertFrom-Json) keeps the array wrapped — foreach runs once, ConvertTo-Json emits {value:[…],Count:n} garbage gotchas / powershell @() around the pipeline doesn't enumerate: foreach over it runs ONCE with the whole array, and a later + nests the array so ConvertTo-Json writes {value:[…],Count:n} garbage; fix with @((ConvertFrom-Json …)) Renaming your SharePoint domain (contosoltd.sharepoint.com to contoso.sharepoint.com) guides Scheduling a tenant rename on a fresh tenant – checking the name is free, adding the matching .onmicrosoft.com domain the right way, the 24-hour scheduling floor (error -772), what -WhatIf and the status output look… Root site swap refuses hub sites, and any site Publishing ever touched gotchas / tooling Invoke-SPOSiteSwap rejects a source or target that is a hub site or associated with one, and rejects a source where the Publishing feature was ever activated — not just currently; unregistering a hub leaves children… SPO Management Shell one-liners every admin ends up needing snippets / cli Quick admin answers — storage top 20, external sharing, deleted sites, lock state — no script file needed What the scripts actually print scripts Bottom line. Every sample below is a real run against a live tenant with the names swapped for Contoso (the one reconstructed sample says so) — including the failures, because knowing what a script looks like when it… Windows PowerShell 5.1 Get-Content/Set-Content mangles UTF-8 — á becomes á gotchas / powershell ANSI default double-encodes diacritics; non-ASCII in the pattern makes -replace match nothing and exit 1. Use System.IO.File + BOM-less UTF8Encoding, check git status after a failed run