PowerShellUsing ShouldProcess

Download PowerShell for free

Syntax

  • $PSCmdlet.ShouldProcess("Target")
  • $PSCmdlet.ShouldProcess("Target", "Action")

Parameters

ParameterDetails
TargetThe resource being changed.
ActionThe operation being performed. Defaults to the name of the cmdlet.

Remarks

$PSCmdlet.ShouldProcess() will also automatically write a message to the verbose output.

PS> Invoke-MyCmdlet -Verbose
VERBOSE: Performing the operation "Invoke-MyCmdlet" on target "Target of action"

Related Examples

Adding -WhatIf and -Confirm support to your cmdlet