Are there any official guidelines from Microsoft about when to add -Confirm
, -Force
, and -WhatIf
parameters to custom PowerShell cmdlets?
As an added observation, -Force
should not overrule -WhatIf
. Or in other words: -WhatIf
has priority over -Force
.
If you use:
Get-ChildItem -Recurse | Remove-Item -Recurse -Force -WhatIf
it will result in the following output:
What if: Performing the operation "Remove Directory" on target "E:\some directory\".
It will not actually remove the items, even when -Force
is specified.
This means that you should never write:
if($Force -or $Pscmdlet.ShouldProcess($)) {
...
}