Use this when automating Windows, AD, Microsoft 365, Azure or VMware with PowerShell.
PowerShell Automation
PowerShell automation uses cmdlets, pipelines of objects, functions, modules and remoting to manage Windows, Active Directory, Microsoft 365, Azure, VMware and more from scripts that run on Windows, Linux and macOS.
1. PowerShell automates Windows (and cross-platform with PowerShell 7).
2. Object pipeline, cmdlets, remoting.
3. Use advanced functions with parameter validation.
4. $ErrorActionPreference = 'Stop' in scripts.
5. Lint and test.
script → cmdlets/objects → remoting → targets
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
Begin with $PSVersionTable, command resolution and module identity, then verify the target-facing operation with read-back. Use Get-Command <name> -All, Get-Module, and the target API/provider query to show which implementation ran. A zero PowerShell error count or a completed pipeline is intermediate evidence; the final evidence is the intended target state observed through an independent read path. If the check only shows an intermediate PowerShell layer, continue to an independent query of the resource or service that owns the required end state.
Step 2 Where it fails Narrow the fault
Do not equate script completion with idempotency, authorization, or target convergence. Execution policy is not a security boundary; a cmdlet success record can precede eventual consistency; native exit status is separate from PowerShell errors; and a remote session can be healthy while the target application is not. Preserve engine/session identity, command source, transport/API state and target read-back as separate evidence layers. Re-run the original consumer-facing operation after remediation and keep the previous evidence for before/after comparison.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
PowerShell fundamentals: cmdlets output objects, the pipeline passes them on, Get-Help and Get-Member explain them, and PowerShell 7 runs cross-platform beside Windows PowerShell 5.1.
Subtopic CmdletsCmdlets are PowerShell's built-in commands named Verb-Noun, such as Get-Service or Set-Item, which output objects.
Subtopic ObjectsPowerShell passes .NET objects, not text, between commands, so properties can be selected, filtered and sorted directly, such as Get-Process | Where-Object CPU -gt 100.
Subtopic PipelineThe PowerShell pipeline passes objects from one command to the next, binding them to parameters by value or property name, such as Get-ADUser -Filter * | Set-ADUser -Department IT.
Subtopic VariablesPowerShell variables start with $, hold any object type and can be strongly typed with [int] or [string].
Subtopic FunctionsPowerShell functions group reusable code with a name and param() block.
Subtopic ModulesPowerShell modules package functions, cmdlets and resources (.psm1 with a .psd1 manifest), installed from the PowerShell Gallery with Install-Module and loaded with Import-Module.
Subtopic ScriptsPowerShell scripts are .ps1 files with parameters, functions and logic.
Subtopic ParametersPowerShell parameters are declared in param() with types, Mandatory, defaults and validation such as ValidateSet or ValidatePattern, so bad input fails before the script acts.
Subtopic Advanced FunctionsAdvanced functions use [CmdletBinding()] and param() with validation attributes, pipeline input, -WhatIf and -Confirm support and verbose output, behaving like compiled cmdlets.
Subtopic Error HandlingPowerShell error handling distinguishes terminating and non-terminating errors.
Subtopic Try / Catch / Finallytry/catch/finally in PowerShell runs code, catches terminating errors (optionally by exception type) and always runs the finally block for cleanup, such as closing sessions.
Subtopic PowerShell RemotingPowerShell Remoting runs commands on other computers with Invoke-Command or Enter-PSSession, over WinRM on Windows or SSH in PowerShell 7, using Kerberos for domain authentication.
Subtopic WinRMWinRM is the Windows service behind PowerShell Remoting, listening on 5985 for HTTP and 5986 for HTTPS.
Subtopic CIMCIM cmdlets (Get-CimInstance, Invoke-CimMethod, New-CimSession) query Windows management data over WS-Man, replacing the older WMI cmdlets and working well remotely.
Subtopic WMIWMI is the older Windows management interface queried with Get-WmiObject in Windows PowerShell.
Subtopic JobsPowerShell jobs run commands in the background with Start-Job or -AsJob, checked with Get-Job and collected with Receive-Job, useful for long or parallel tasks.
Subtopic Parallel ExecutionParallel execution in PowerShell 7 uses ForEach-Object -Parallel with -ThrottleLimit, while Invoke-Command runs on many remote computers at once.
Subtopic Scheduled JobsPowerShell scheduled jobs (Register-ScheduledJob) or scheduled tasks (Register-ScheduledTask) run scripts on a schedule; use a service account or gMSA and log output to a file.
Subtopic CredentialsPowerShell credentials are PSCredential objects created with Get-Credential or from SecretManagement, passed to -Credential parameters.
Subtopic SecretManagementSecretManagement is a PowerShell module that gives one interface (Get-Secret, Set-Secret) to vaults such as SecretStore, Azure Key Vault or KeePass, keeping secrets out of scripts.
Subtopic REST APIsPowerShell calls REST APIs with Invoke-RestMethod, which converts JSON responses to objects, supports headers, bodies, authentication and, in PowerShell 7, retries with -MaximumRetryCount.
Subtopic JSONPowerShell handles JSON with ConvertFrom-Json to turn text into objects and ConvertTo-Json -Depth to serialize, since the default depth of 2 silently truncates nested data.
Subtopic XMLPowerShell handles XML with [xml] type casting, Select-Xml with XPath, and Export-Clixml and Import-Clixml for saving objects, including encrypted credentials for the same user.
Subtopic CSVPowerShell handles CSV with Import-Csv, which turns rows into objects with properties from the header, and Export-Csv -NoTypeInformation for reports.
Subtopic PowerShell TroubleshootingTroubleshoot PowerShell scripts with Set-PSDebug, Write-Verbose and -Verbose, inspecting $Error[0] | Format-List * -Force, the execution policy, module versions and the PowerShell edition in use.
- PowerShell passes objects, not text.
- Use -WhatIf before bulk changes.
- Set $ErrorActionPreference = 'Stop' so try/catch works.
$PSVersionTable— PowerShell version/editionInvoke-ScriptAnalyzer -Path . -Recurse— lintInvoke-Pester— tests
ReferenceWhy it matters1 section · depth on demand
In depth
PowerShell automation uses PowerShell's object pipeline, cmdlets and modules to manage Windows, Microsoft 365, Azure, VMware and many other platforms. Because cmdlets return objects, you can filter and format data without parsing text.
| Area | Modules |
|---|---|
| Windows/AD | ActiveDirectory, GroupPolicy, DnsServer |
| Azure | Az |
| Microsoft 365/Entra | Microsoft.Graph, ExchangeOnlineManagement |
| VMware | VCF.PowerCLI |
| Remoting | Built-in WinRM and SSH remoting |
Get-ADUser -Filter 'Enabled -eq $false' -SearchBase 'OU=Staff,DC=corp,DC=example,DC=com' | Select-Object Name, LastLogonDate | Export-Csv disabled.csv -NoTypeInformation
Prefer PowerShell 7 for new automation; keep Windows PowerShell 5.1 for modules that still require it.
ReferenceImportant terms & boundaries2 sections · depth on demand
Platform, version and operating-envelope scope
PowerShell 5.1/7+, module versions and remoting endpoint behavior vary by host/platform.
PowerShell mechanics
PowerShell automation is an engine-and-runspace execution model, not merely a shell script launcher. Command discovery and parameter binding select the executable command, objects move through typed success/output streams, providers expose data stores through PowerShell drives, and native processes form a separate boundary with their own exit codes. The host, PowerShell edition, loaded modules, runspace/session state and target API or transport together determine what a command actually means.
ReferenceConfiguration & state1 section · depth on demand
Authoring and lifecycle
Treat the script or module repository as persistent intent and the running session as derived state. Pin required module versions where reproducibility matters, declare prerequisites instead of relying on interactive profile state, separate secret acquisition from business logic, and make repeated execution safe by reading current target state before mutation. Automation that crosses remoting, REST or native-process boundaries must record those boundaries explicitly because each has different authentication, serialization and failure semantics.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Review target identity, permissions and environment before mutation.
#Requires -Version 7.2
Set-StrictMode -Version LatestVerification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/powershell/ · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Quick lookup tables
PowerShell Automation · PowerShell operational reference
Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.
| Boundary | PowerShell Automation reference |
|---|---|
| Runtime identity | PowerShell edition/version + command/module source |
| Persistent intent | Script/module/config prerequisites under source control |
| Verification | Read-only discovery → execution evidence → independent target read-back |
| Output contract | Structured objects/streams before formatting |
| Failure boundary | Separate engine/binding from transport/API/native and target-state failures |
Deep reference
Healthy vs suspicious evidence
Output interpretation
Interpret PowerShell output as objects and streams before formatting. Capture object type and relevant properties, the error stream/ErrorRecord where applicable, and $LASTEXITCODE for native executables. Formatting output is presentation and should not be used as a machine-readable contract. For remote commands, remember that returned objects may be deserialized representations rather than live local instances. This makes future runs comparable even when the host changes table width, formatting views or property display order.