PowerShell
Articles in the PowerShell category (42).
Articles in the PowerShell category (42).
- AzureAD: list and remove group memberships (PowerShell) — List the groups of an Azure AD user or service principal and remove it from them with PowerShell.
- CPU stress test with PowerShell — PowerShell script that starts background jobs to load the CPU, with commands to list and stop them.
- Create a local PowerShell repository and install a module from it — Register a local folder as a PowerShell repository and install a module from a .nupkg package.
- Culture and UI culture in PowerShell — Read, set and list cultures in PowerShell, and change the language of the help.
- HTML e-mail reports from PowerShell that look good on phone and desktop — Structure, inline CSS, status colours, tables and sending of an HTML report that renders well on phone and desktop.
- Inspecting and rethrowing PowerShell errors — Inspect PowerShell errors ($Error, call stack) and rethrow exceptions with context.
- Load public and private functions in a PowerShell module — Automatically load the public (exported) and private functions of a PowerShell module from the public and private folders.
- Logging standards for scheduled PowerShell jobs — Levels, structured lines, a correlation id per run, where logs go (file, Log Analytics), what never to log, and Write-Host pitfalls in non-interactive runs.
- Manage Windows DNS records with PowerShell — List DNS zones and records and change the address of an A record with the DnsServer module.
- Ordered shutdown and startup of a SharePoint farm with PowerShell — Two PowerShell scripts to stop and start the servers of a SharePoint farm in the right order (front-end, OWA, application, database).
- Per-environment configuration for PowerShell scripts: JSON, Key Vault, App Configuration — config-env.json files, a Set-Parameters style loader, consistency checks across environments, secrets in Key Vault, and Azure App Configuration as an option.
- PowerShell and Active Directory: Get-ADUser examples — Find users, expired accounts, groups, CSV exports and photos with the ActiveDirectory cmdlets.
- PowerShell equivalents of classic network commands — PowerShell cmdlets replacing ipconfig, ping, nslookup, route, tracert and netstat.
- PowerShell execution policy: check, change and run scripts — Check and change the PowerShell execution policy per scope, unblock downloaded scripts and run scripts from a network share.
- PowerShell logger with levels and log rotation — PowerShell Write-Log function with severity levels, colored output and size-based log file rotation.
- PowerShell special characters and tokens — Quick reference for PowerShell comparison operators, escape sequences and special tokens.
- PowerShell: convert a string to a byte array (UTF-8) — Get the bytes of a string with [System.Text.Encoding]::UTF8.GetBytes().
- PowerShell: force TLS 1.2 ("unexpected error occurred on a send") — Check and force TLS 1.2 in PowerShell and .NET, verify SCHANNEL/WinHTTP registry settings, and skip certificate checks for tests.
- PowerShell: free space of a network share with event log alerts — Map a share, compute the free percentage and write a Warning or Error event.
- PowerShell: get the current script path and name — Comparison of $PSCommandPath and the $MyInvocation properties, in a script and inside a function.
- PowerShell: get the IP address of a cluster resource — Read a cluster IP address resource with Get-ClusterResource and Get-ClusterParameter.
- PowerShell: inspect PSReadLine colours — Show PSReadLine colour options and the PowerShell version.
- PowerShell: last logon time of Active Directory users — PowerShell script that queries every domain controller to export each AD user's real last logon time.
- PowerShell: list the records of a Windows DNS zone — Use Get-DnsServerResourceRecord to list the records of a zone on a Windows DNS server.
- PowerShell: module paths and updates — How PSModulePath works, importing modules from outside the path, install scopes and updating modules.
- PowerShell: prevent the session from sleeping or locking — PowerShell scripts that simulate a key press or a mouse movement at regular intervals to prevent sleep or screen locking.
- PowerShell: retrieve the Windows product key of a computer — PowerShell function that decodes DigitalProductId through WMI to show the Windows product key of a local or remote computer.
- PowerShell: run a script as another account with a stored credential — CredentialManager, Get-StoredCredential and Start-Process -Credential to run a script without typing a password.
- PowerShell: run an SSH command through a bastion (ProxyJump) — Run a command on a Linux server behind a bastion with OpenSSH -J, or with Posh-SSH.
- PowerShell: script template with help header and logging — PowerShell script skeleton (help, initialisation, functions, logging) based on a public gist.
- PowerShell: search files by name, regex or content — Get-ChildItem and Select-String cheat sheet to find files.
- PowerShell: show free disk space of volumes — Win32_Volume WMI query with calculated properties to list capacity, free space and free percentage.
- PowerShell: tail -f equivalent with Get-Content — Follow and filter a log file with Get-Content -Tail -Wait and Select-String.
- PowerShell: testing for null or empty strings — How $null, empty and whitespace strings behave in an if condition and with IsNullOrEmpty.
- PowerShell: wipe and re-initialize a disk with Clear-Disk — Clear-Disk -RemoveData to completely wipe a disk before re-initializing it (destructive command).
- Publish a PowerShell module to an Azure Artifacts feed — Register an Azure Artifacts feed as a private PowerShell repository and publish a module with PowerShellGet, PSResourceGet or nuget.
- Retention policy for .bacpac files on Azure Files with PowerShell — PowerShell script that mounts an Azure Files share and keeps one bacpac per week, per month, then per year.
- Running an SSH command from PowerShell with Posh-SSH — Open an SSH session, run a command and close it from PowerShell with the Posh-SSH module.
- Running one query on hundreds of Azure SQL databases with PowerShell — Build the target list, parallelise with ForEach-Object -Parallel, reuse the Entra token, handle timeouts and retries, and produce a results CSV plus a failure report.
- Show local time and convert it to UTC in PowerShell — Show the date and UTC offset with Get-Date -UFormat, and convert a date to UTC with ToUniversalTime().
- Structuring a PowerShell module for DBA work — Manifest, Classes/Private/Public folders, loader, SQL templates with placeholders, versioning, and the module / application / tool boundary.
- Testing SQL-facing PowerShell code with Pester, without a database — Mocking the data access layer, testing SQL templates and config files, and running the tests in CI without a database.