Cmdlet::ShouldProcess Method (String^, String^)
Updated: April 27, 2016
Applies To: Windows PowerShell
Requests confirmation from the user before an operation is performed. This method sends the operation that is to be performed and the name of the resource to be changed so that the user can decide if the operation should continue.
Assembly: System.Management.Automation (in System.Management.Automation.dll)
The name of the resource to be changed. To see how the resource is displayed in the confirmation message, see the following code examples.
The operation to be performed. To see how the operation 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.
Also, if the pipeline was terminated because of ActionPreference.Stop or ActionPreference.Inquire, the command failure will ultimately be ActionPreferenceStopException.
The call cannot be completed at this time or cannot be completed from this thread. For more information, see the following Remarks section.
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 this method, the cmdlet must also set the SupportsShouldProcess parameter of its cmdlet attribute declaration to true. For more information about the syntax and declaration of this attribute, see CmdletAttribute Declaration.
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 the resource that the cmdlet will act upon and the operation to be performed.