使用 ShouldProcess
$PSCmdlet.ShouldProcess()
還會自動將訊息寫入詳細輸出。
PS> Invoke-MyCmdlet -Verbose
VERBOSE: Performing the operation "Invoke-MyCmdlet" on target "Target of action"
$PSCmdlet.ShouldProcess()
還會自動將訊息寫入詳細輸出。
PS> Invoke-MyCmdlet -Verbose
VERBOSE: Performing the operation "Invoke-MyCmdlet" on target "Target of action"