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.

Cmdlet.ShouldContinue Method (String, String, Boolean, Boolean)


Updated: April 27, 2016

Applies To: Windows PowerShell

Requests confirmation of an operation from the user by sending a second query to the user with yesToall and noToall options.

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

Public Function ShouldContinue (
	query As String,
	caption As String,
	ByRef yesToAll As Boolean,
	ByRef noToAll As Boolean
) As Boolean


Type: System.String

Query that inquires whether the cmdlet should continue.

Type: System.String

Caption of the window that might be displayed when the user is prompted whether or not to perform the action. It might be displayed by some hosts, but not by all hosts.

Type: System.Boolean

True if and only if the user selects the yesToall option. If this is already True, ShouldContinue will bypass the prompt and return True.

Type: System.Boolean

True if and only if the user selects the noToall option. If this is already True, ShouldContinue will bypass the prompt and return False.

Return Value

Type: System.Boolean

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

Exception Condition

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 is typically called after a call to ShouldProcess method to provide additional feedback from the user. For more information about confirmation requests, see Requesting Confirmation.

A call to the ShouldContinue method is not affected by preference settings or command-line parameters; the query is always displayed to the user.

Cmdlets calling ShouldContinue should also implement a Force parameter that allows the cmdlet to bypass these calls. If this is not done, it will be difficult to use the cmdlet from scripts and noninteractive hosts.

This method can be called only from within the cmdlet implementation of the BeginProcessing, ProcessRecord, and EndProcessing methods and only from that thread. If this call is made from outside these implementations or from another thread, an InvalidOperationException exception is thrown.

For more information about cmdlets, see Windows PowerShell Cmdlets.

In the following code example, the call to ShouldContinue does not specify a caption or query so the default text is displayed. In addition, the yesToAll parameter is set to true, which means that the second message is displayed only if the user answered Yes To All to the first confirmation message.

private bool yesToAll;
private bool noToAll;
protected override void ProcessRecord()
  if (ShouldProcess("ShouldProcess target"))
    if (Force || ShouldContinue("ShouldContinue query",
                                "ShouldContinue caption",
                                ref yesToAll,
                                ref noToAll))
      // Add code that performs the operation.

The first message is displayed as a result of the call to the Cmdlet.ShouldProcess method. The second message is displayed as a result of the call to the ShouldContinue method when the user answers Yes to All to the first message. Notice that in this case the default confirmation message is displayed.

Are you sure you want to perform this action?
Performing operation "Test-RequestConfirmationTemplate1" on Target "Resource".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

Continue with this operation?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):
Return to top

Community Additions