Add [CmdletBinding()] to a PowerShell function to turn it into an advanced function. PowerShell then supplies common parameters such as -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable, and -PipelineVariable. section 11.1
Use the attribute as the foundation for practical automation features:
- Accept pipeline input by combining CmdletBinding with [Parameter(ValueFromPipeline=$True)] and processing input through BEGIN, PROCESS, and END blocks. section 11.1.1
- Support -WhatIf and -Confirm by setting SupportsShouldProcess=$True, choosing ConfirmImpact, and guarding risky operations with $PSCmdlet.ShouldProcess(). section 11.1.5
- Extend parameter design with mandatory parameters, validation, aliases, parameter sets, and—when appropriate—dynamic parameters. section 11.3 section 11.1.4
Upgrade a function
function Get-MachineInfo { [CmdletBinding()] Param( [Parameter(ValueFromPipeline=$True)] [string[]]$ComputerName ) BEGIN { } PROCESS { foreach ($computer in $ComputerName) { # Query each computer here } } END { Write-Output "All Done" } } Get-MachineInfo -ComputerName ONE,TWO,THREE "ONE","TWO","THREE" | Get-MachineInfo The same function can accept direct arguments or pipeline input, while its help syntax exposes [<CommonParameters>]. section 11.1.1
Function Set-Something {
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')]
Param(
)
} #function
Use SupportsShouldProcess and ConfirmImpact when a function changes system state; pair them with ShouldProcess around operations that need WhatIf or confirmation. section 11.1.5

