Cmdlet.ShouldContinue Method

Definition

Overloads

ShouldContinue(String, String)

Confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant only offers Yes/No, not YesToAll/NoToAll.

ShouldContinue(String, String, Boolean, Boolean)

Confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant offers Yes, No, YesToAll and NoToAll.

ShouldContinue(String, String, Boolean, Boolean, Boolean)

ShouldContinue(String, String)

Confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant only offers Yes/No, not YesToAll/NoToAll.

public bool ShouldContinue (string query, string caption);
Parameters
query
String

Textual query of whether the action should be performed, usually in the form of a question.

caption
String

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

Returns

If ShouldContinue returns true, the operation should be performed. If ShouldContinue returns false, the operation should not be performed, and the Cmdlet should move on to the next target resource.

Exceptions

The pipeline has already been terminated, or was terminated during the execution of this method. The Cmdlet should generally just allow PipelineStoppedException to percolate up to the caller of ProcessRecord etc.

Not permitted at this time or from this thread. ShouldContinue may only be called during a call to this Cmdlet's implementation of ProcessRecord, BeginProcessing or EndProcessing, and only from that thread.

Remarks

Cmdlets using ShouldContinue should also offer a "bool Force" parameter which bypasses the calls to ShouldContinue and ShouldProcess. If this is not done, it will be difficult to use the Cmdlet from scripts and non-interactive hosts.

        Cmdlets using ShouldContinue must still verify operations
        which will make changes using ShouldProcess.
        This will assure that settings such as -WhatIf work properly.
        You may call ShouldContinue either before or after ShouldProcess.

        ShouldContinue may only be called during a call to this Cmdlet's
        implementation of ProcessRecord, BeginProcessing or EndProcessing,
        and only from that thread.

        Cmdlets may have different "classes" of confirmations.  For example,
        "del" confirms whether files in a particular directory should be
        deleted, whether read-only files should be deleted, etc.
        Cmdlets can use ShouldContinue to store YesToAll/NoToAll members
        for each such "class" to keep track of whether the user has
        confirmed "delete all read-only files" etc.
        ShouldProcess offers YesToAll/NoToAll automatically,
        but answering YesToAll or NoToAll applies to all subsequent calls
        to ShouldProcess for the Cmdlet instance.

ShouldContinue(String, String, Boolean, Boolean)

Confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant offers Yes, No, YesToAll and NoToAll.

public bool ShouldContinue (string query, string caption, ref bool yesToAll, ref bool noToAll);
Parameters
query
String

Textual query of whether the action should be performed, usually in the form of a question.

caption
String

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

yesToAll
Boolean

true iff user selects YesToAll. If this is already true, ShouldContinue will bypass the prompt and return true.

noToAll
Boolean

true iff user selects NoToAll. If this is already true, ShouldContinue will bypass the prompt and return false.

Returns

If ShouldContinue returns true, the operation should be performed. If ShouldContinue returns false, the operation should not be performed, and the Cmdlet should move on to the next target resource.

Exceptions

The pipeline has already been terminated, or was terminated during the execution of this method. The Cmdlet should generally just allow PipelineStoppedException to percolate up to the caller of ProcessRecord etc.

Not permitted at this time or from this thread. ShouldContinue may only be called during a call to this Cmdlet's implementation of ProcessRecord, BeginProcessing or EndProcessing, and only from that thread.

Remarks

Cmdlets using ShouldContinue should also offer a "bool Force" parameter which bypasses the calls to ShouldContinue and ShouldProcess. If this is not done, it will be difficult to use the Cmdlet from scripts and non-interactive hosts.

        Cmdlets using ShouldContinue must still verify operations
        which will make changes using ShouldProcess.
        This will assure that settings such as -WhatIf work properly.
        You may call ShouldContinue either before or after ShouldProcess.

        ShouldContinue may only be called during a call to this Cmdlet's
        implementation of ProcessRecord, BeginProcessing or EndProcessing,
        and only from that thread.

        Cmdlets may have different "classes" of confirmations.  For example,
        "del" confirms whether files in a particular directory should be
        deleted, whether read-only files should be deleted, etc.
        Cmdlets can use ShouldContinue to store YesToAll/NoToAll members
        for each such "class" to keep track of whether the user has
        confirmed "delete all read-only files" etc.
        ShouldProcess offers YesToAll/NoToAll automatically,
        but answering YesToAll or NoToAll applies to all subsequent calls
        to ShouldProcess for the Cmdlet instance.

ShouldContinue(String, String, Boolean, Boolean, Boolean)

public bool ShouldContinue (string query, string caption, bool hasSecurityImpact, ref bool yesToAll, ref bool noToAll);
Parameters
query
String
caption
String
hasSecurityImpact
Boolean
yesToAll
Boolean
noToAll
Boolean
Returns