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

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)

Dim instance As Cmdlet
Dim query As String
Dim caption As String
Dim yesToAll As Boolean
Dim noToAll As Boolean
Dim returnValue As Boolean

returnValue = instance.ShouldContinue(query, caption, yesToAll, noToAll)

Public Function ShouldContinue ( _
	query As String, _
	caption As String, _
	ByRef yesToAll As Boolean, _
	ByRef noToAll As Boolean _
) As Boolean
public boolean ShouldContinue (
	String query, 
	String caption, 
	/** @ref */ boolean yesToAll, 
	/** @ref */ boolean noToAll



Query that inquires whether the cmdlet should continue.


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.


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


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

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.

In the following code example, the call to ShouldContinue(String,String,Boolean,Boolean) 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(String) method. The second message is displayed as a result of the call to the ShouldContinue(String,String,Boolean,Boolean) 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"):

Exception typeCondition

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Target Platforms

© 2015 Microsoft