if ($PSCmdlet.ShouldProcess("Target of action")) {
# Do the thing
}
When using -WhatIf
:
What if: Performing the action "Invoke-MyCmdlet" on target "Target of action"
When using -Confirm
:
Are you sure you want to perform this action? Performing operation "Invoke-MyCmdlet" on target "Target of action" [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):