My advanced script (with [CmdletBinding(SupportsShouldProcess)]
attribute) calls a native command. That native command supports a switch that causes it to run in "dry run" mode, i.e., just outputting what would be copied or deleted without actually doing any copying/deleting.
Sample code of the script:
[CmdletBinding(SupportsShouldProcess)]
param ()
gsutil -m rsync -r -n something gs://something
Here the -n
switch turns on the dry run mode.
How can I specify this switch based on whether WhatIf
switch was passed to my script?
According to this official article, other cmdlets should inherit -WhatIf
values automatically, but still it is suggested to explicitly pass the value to the cmdlets: -WhatIf:$WhatIfPreference
. But in the call to a native command, I suppose, this approach doesn't work.