Use this when writing PowerShell functions that behave like cmdlets.
Advanced Functions
Advanced functions use [CmdletBinding()] and param() with validation attributes, pipeline input, -WhatIf and -Confirm support and verbose output, behaving like compiled cmdlets.
1. Advanced functions behave like cmdlets: [CmdletBinding()], common parameters, ShouldProcess.
2. Support -WhatIf for changes.
3. Pipeline input.
4. Write-Verbose for details.
5. Return objects.
[CmdletBinding()] → common params + ShouldProcess → actions
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
Inspect the command with Get-Command to show CmdletBinding, common parameters and parameter sets. Test direct and pipeline invocations, -WhatIf/-Confirm paths if supported, plus terminating and non-terminating failure cases. Verify target state after a real mutation because ShouldProcess only controls whether the function chooses to attempt it.
Step 2 Common mistakes Narrow the fault
- Missing
SupportsShouldProcesson functions that change things.
Step 3 Where it fails Narrow the fault
SupportsShouldProcess is not evidence that every mutation is protected; the implementation must invoke ShouldProcess. Common-parameter availability does not make a function idempotent or transaction-safe. Separate the advanced-function interface, lifecycle block behavior, side-effect gating and final target-evidence of the actual state.
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.
- [CmdletBinding()] adds common parameters.
- SupportsShouldProcess enables -WhatIf/-Confirm.
- Validation attributes reject bad input.
- CmdletBinding(SupportsShouldProcess) — -WhatIf/-Confirm
- begin/process/end blocks — pipeline
Get-Help <function> -Full— help
ReferenceWhy it matters1 section · depth on demand
In depth
Advanced functions use [CmdletBinding()] to behave like compiled cmdlets: they get common parameters (-Verbose, -ErrorAction, -WhatIf, -Confirm), pipeline processing blocks, and ShouldProcess support for safe changes.
function Set-PortDescription {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(Mandatory, ValueFromPipelineByPropertyName)][string]$Switch,
[Parameter(Mandatory, ValueFromPipelineByPropertyName)][string]$Port,
[Parameter(Mandatory, ValueFromPipelineByPropertyName)][string]$Description
)
process {
if ($PSCmdlet.ShouldProcess("$Switch $Port", "set description '$Description'")) {
Write-Verbose "Updating $Switch $Port"
# API/SSH call here
}
}
}
Import-Csv ports.csv | Set-PortDescription -WhatIf
The process block runs once per piped object, so the function works equally for one port or thousands from a CSV.
ReferenceImportant terms & boundaries1 section · depth on demand
PowerShell mechanics
Advanced functions use [CmdletBinding()] and parameter metadata so script functions participate in cmdlet-like semantics such as common parameters, parameter sets and $PSCmdlet. begin, process, end and clean provide lifecycle hooks for pipeline processing. SupportsShouldProcess enables the ShouldProcess() contract used by -WhatIf and -Confirm when the function author actually gates mutations through it.
ReferenceConfiguration & state1 section · depth on demand
Authoring and lifecycle
Use advanced functions for reusable automation where a stable command contract matters. Keep side effects behind ShouldProcess when appropriate, emit structured objects, use verbose/error streams for diagnostics, and declare pipeline binding intentionally. Avoid turning every helper into an advanced function; choose it when cmdlet semantics materially improve the interface.
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.
function Set-DemoState { [CmdletBinding(SupportsShouldProcess)] param([string]$Name) if ($PSCmdlet.ShouldProcess($Name,"Update")) { [pscustomobject]@{Name=$Name;Changed=$true} } }Verification 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/module/microsoft.powershell.core/about/about_functions_advanced?view=powershell-7.5 · confidence 94%Quick lookup tables
Advanced Functions · PowerShell operational reference
Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.
| Boundary | Advanced Functions 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
Advanced functions can still emit accidental success-stream objects, and common parameters affect engine behavior rather than business success. Write-Error behavior depends on terminating semantics, while $PSCmdlet.ThrowTerminatingError() creates a different control-flow boundary. Capture ErrorRecord details and structured function output separately.