WhatIf?
Function Push-Me {
[CmdletBinding(SupportsShouldProcess)]
Param([Parameter(ValueFromRemainingArguments)] $args)
if ($PSCmdlet.ShouldProcess($args)) {
git push @args
}
else {
git push --dry-run @args
}
}
Push-Me -Confirm
Push-Me -WhatIf
[CmdletBinding(SupportsShouldProcess)]
enables this$PSCmdlet.ShouldProcess(...)
is what is to be run- the
else
clause is not necessary unless for customWhatIf
output
$args
is not available in advanced functions (as defined by CmdletBinding
)