ShouldProcess
noun
say it: “shood PROH-ses” /ʃʊd ˈprɑsɛs/
The question a PowerShell function asks before each change, which says yes, prints a What if line, or asks the person first.
What does ShouldProcess do?
$PSCmdlet.ShouldProcess() is the question a function asks before each change: "should I go ahead with this one?" Normally the answer is yes. Under -WhatIf it prints a What if: line with your target and action and answers no; under -Confirm it asks the person.
if ($PSCmdlet.ShouldProcess($Song.Title, 'Remove song')) { <# remove it #> }
# with -WhatIf:
# What if: Performing the operation "Remove song" on target "Rainy Overpass".
In a sentence
- “The target Sam gave ShouldProcess became the song's title in the What if line.”
- “Each removal is wrapped in ShouldProcess, so -WhatIf printed three lines and removed nothing.”
Level: Freelancer · More PowerShell terms at this level
Updated