Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CmdletProvider.ShouldProcess Method (String, String)

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Confirms the operation with the user, sending the name of the resource to be changed and the action to be performed to the user for confirmation before the operation is performed.

Namespace:   System.Management.Automation.Provider
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

Public Function ShouldProcess (
	target As String,
	action As String
) As Boolean

Parameters

target
Type: System.String

The name of the resource to be changed.

action
Type: System.String

The action to be taken.

Return Value

Type: System.Boolean

A Boolean value that indicates true when the user wants the provider to perform the operation. If false is returned, the operation should not be performed and the provider should move to the next resource.

Exception Condition
PipelineStoppedException

The pipeline is stopped. The pipeline was terminated either before the call was made or while the call was in progress. In general, the Windows PowerShell provider 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.

To call this method, the provider must specify that it supports calls to the ShouldProcess(String, String, String) method when the CmdletProviderAttribute attribute is declared.

When the provider calls the ShouldProcess(String, String, String) method, the Windows PowerShell runtime handles any command-line settings or preference variables when it determines what is shown to the user or what should be returned.

Windows PowerShell provides two methods that the Windows PowerShell provider can call to confirm an operation with the user: ShouldProcess and ShouldContinue. The second method, the ShouldContinue method, is used to get a confirmation from the user in cases where the change is significant or when you want to provide yes-to-all and no-to-all options to the user. In addition, in contrast to ShouldProcess calls, a call to ShouldContinue is not affected by command-line settings or preference variables; the query is always displayed to the user.

For more information about providers, see Windows PowerShell Providers [ps].

Return to top

Community Additions

Show: