Cmdlet.ShouldProcess Method (String, String, String)
Updated: April 27, 2016
Applies To: Windows PowerShell
Requests confirmation from the user before an operation is performed. This method sends a description of the operation to be performed, a warning message that can include query, and a caption for the warning message.
Assembly: System.Management.Automation (in System.Management.Automation.dll)
public bool ShouldProcess( string verboseDescription, string verboseWarning, string caption )
A description of the operation to be performed. This description is displayed to the user when a Warning message is not specified, when the WhatIf parameter is used when the command is called, or when the ErrorActionPreference variable is set to Continue. To see how the warning is displayed in the confirmation message, see the following code examples.
A warning message that contains a query asking whether the operation should be performed. This warning message is displayed to the user when the ErrorActionPreference variable is set to Inquire. To see how the warning is displayed in the confirmation message, see the following code examples.
A caption for the warning message. This caption can also displayed in a window that might, or might not, be displayed by specific hosts. To see how the caption is displayed in the confirmation message, see the following code examples.
The pipeline is stopped. The pipeline was terminated either before the call was made or while the call was in progress. By default, the cmdlet should allow the caller of the processing record method to catch this exception.
The call cannot be completed at this time or cannot be completed from this thread. For more information, see the following Remarks section.
This variant provides maximum control over the confirmation message that is presented to the user and the warning that is presented to the user if the user is informed of the operation, but not explicitly prompted. This method should be called before the cmdlet makes a change to the system. For more information about confirmation requests, including information about how confirmation requests are affected by the $ConfirmPreference shell variable, see Requesting Confirmation.
To call CmdletAttribute Declaration., the cmdlet must also set the SupportsShouldProcess parameter of its Cmdlet attribute declaration to true. For more information about the syntax and declaration parameter of this attribute, see
This method can be called only from within the cmdlet input processing methods (BeginProcessing, ProcessRecord, and EndProcessing) and only from that thread. If this call is made from outside these methods or from another thread, an InvalidOperationException exception is thrown.
When this method is called, the runspace checks any command-line settings or preference variables when it determines what should be returned or what is displayed to the user.
For more information about cmdlets, see Windows PowerShell Cmdlets.
In the following code example, thecall specifies a description, warning, and a caption.