Tutorial by Examples

function Invoke-MyCmdlet { [CmdletBinding(SupportsShouldProcess = $true)] param() # ... }
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 &qu...
Other examples couldn't clearly explain to me how to trigger the conditional logic. This example also shows that underlying commands will also listen to the -Confirm flag! <# Restart-Win32Computer #> function Restart-Win32Computer { [CmdletBinding(SupportsShouldProcess=$true,Conf...

Page 1 of 1