SupportsShouldProcess
noun
say it: “suh-PORTS shood PROH-ses” /səˈpɔrts ʃʊd ˈprɑsɛs/
A setting in a PowerShell function's CmdletBinding that gives it -WhatIf and -Confirm, so its changes can be rehearsed.
What does SupportsShouldProcess do?
SupportsShouldProcess inside [CmdletBinding()] gives your function the same safety switches Remove-Item has: -WhatIf to rehearse and -Confirm to ask first. A tool that removes or changes something should have it; a Get- tool only reads, so it doesn't.
function Remove-Song {
[CmdletBinding(SupportsShouldProcess)]
param([Parameter(ValueFromPipeline)] $Song)
process { if ($PSCmdlet.ShouldProcess($Song.Title, 'Remove song')) { <# remove it #> } }
}
In a sentence
- “With SupportsShouldProcess, Remove-Song -WhatIf only said what it would remove.”
- “Sam added SupportsShouldProcess to every tool that deletes something.”
Level: Freelancer · More PowerShell terms at this level
Updated