Cmdlet.ShouldContinue Cmdlet.ShouldContinue Cmdlet.ShouldContinue Method

Definition

Overloads

ShouldContinue(String, String) ShouldContinue(String, String) 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) ShouldContinue(String, String, Boolean, Boolean) 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, Boolean, Boolean, Boolean) ShouldContinue(String, String, Boolean, 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) ShouldContinue(String, String) 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);
member this.ShouldContinue : string * string -> bool
Public Function ShouldContinue (query As String, caption As String) As Boolean
Parameters
query
String String String

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

caption
String String 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.

Examples

namespace Microsoft.Samples.MSH.Cmdlet { [Cmdlet(VerbsCommon.Remove,"myobjecttype4")] public class RemoveMyObjectType4 : Cmdlet { [Parameter( Mandatory = true )] public string Filename { get { return filename; } set { filename = value; } } private string filename; [Parameter] public SwitchParameter Force { get { return force; } set { force = value; } } private bool force; public override void ProcessRecord() { if (ShouldProcess( String.Format("Deleting file {0}",filename), String.Format("Are you sure you want to delete file {0}", filename), "Delete file")) { if (IsReadOnly(filename)) { if (!Force && !ShouldContinue( String.Format("File {0} is read-only. Are you sure you want to delete read-only file {0}?", filename), "Delete file")) ) { return; } } // delete the object } } } } namespace Microsoft.Samples.MSH.Cmdlet { [Cmdlet(VerbsCommon.Remove,"myobjecttype4")] public class RemoveMyObjectType4 : Cmdlet { [Parameter( Mandatory = true )] public string Filename { get { return filename; } set { filename = value; } } private string filename; [Parameter] public SwitchParameter Force { get { return force; } set { force = value; } } private bool force; public override void ProcessRecord() { if (ShouldProcess( String.Format("Deleting file {0}",filename), String.Format("Are you sure you want to delete file {0}", filename), "Delete file")) { if (IsReadOnly(filename)) { if (!Force && !ShouldContinue( String.Format("File {0} is read-only. Are you sure you want to delete read-only file {0}?", filename), "Delete file")) ) { return; } } // delete the object } } } }

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.
See Also

ShouldContinue(String, String, Boolean, Boolean) ShouldContinue(String, String, Boolean, Boolean) 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);
member this.ShouldContinue : string * string *  *  -> bool
Public Function ShouldContinue (query As String, caption As String, ByRef yesToAll As Boolean, ByRef noToAll As Boolean) As Boolean
Parameters
query
String String String

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

caption
String String 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 Boolean Boolean

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

noToAll
Boolean Boolean 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.

Examples

namespace Microsoft.Samples.MSH.Cmdlet { [Cmdlet(VerbsCommon.Remove,"myobjecttype4")] public class RemoveMyObjectType5 : Cmdlet { [Parameter( Mandatory = true )] public string Filename { get { return filename; } set { filename = value; } } private string filename; [Parameter] public SwitchParameter Force { get { return force; } set { force = value; } } private bool force; private bool yesToAll; private bool noToAll; public override void ProcessRecord() { if (ShouldProcess( String.Format("Deleting file {0}",filename), String.Format("Are you sure you want to delete file {0}", filename), "Delete file")) { if (IsReadOnly(filename)) { if (!Force && !ShouldContinue( String.Format("File {0} is read-only. Are you sure you want to delete read-only file {0}?", filename), "Delete file"), ref yesToAll, ref noToAll ) { return; } } // delete the object } } } } namespace Microsoft.Samples.MSH.Cmdlet { [Cmdlet(VerbsCommon.Remove,"myobjecttype4")] public class RemoveMyObjectType5 : Cmdlet { [Parameter( Mandatory = true )] public string Filename { get { return filename; } set { filename = value; } } private string filename; [Parameter] public SwitchParameter Force { get { return force; } set { force = value; } } private bool force; private bool yesToAll; private bool noToAll; public override void ProcessRecord() { if (ShouldProcess( String.Format("Deleting file {0}",filename), String.Format("Are you sure you want to delete file {0}", filename), "Delete file")) { if (IsReadOnly(filename)) { if (!Force && !ShouldContinue( String.Format("File {0} is read-only. Are you sure you want to delete read-only file {0}?", filename), "Delete file"), ref yesToAll, ref noToAll ) { return; } } // delete the object } } } }

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.
See Also

ShouldContinue(String, String, Boolean, Boolean, Boolean) ShouldContinue(String, String, Boolean, Boolean, Boolean) ShouldContinue(String, String, Boolean, 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, bool hasSecurityImpact, ref bool yesToAll, ref bool noToAll);
member this.ShouldContinue : string * string * bool *  *  -> bool
Public Function ShouldContinue (query As String, caption As String, hasSecurityImpact As Boolean, ByRef yesToAll As Boolean, ByRef noToAll As Boolean) As Boolean
Parameters
query
String String String

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

caption
String String 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.

hasSecurityImpact
Boolean Boolean Boolean

true if the operation being confirmed has a security impact. If specified, the default option selected in the selection menu is 'No'.

yesToAll
Boolean Boolean Boolean

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

noToAll
Boolean Boolean 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.

Examples

namespace Microsoft.Samples.MSH.Cmdlet { [Cmdlet(VerbsCommon.Remove,"myobjecttype4")] public class RemoveMyObjectType5 : Cmdlet { [Parameter( Mandatory = true )] public string Filename { get { return filename; } set { filename = value; } } private string filename; [Parameter] public SwitchParameter Force { get { return force; } set { force = value; } } private bool force; private bool yesToAll; private bool noToAll; public override void ProcessRecord() { if (ShouldProcess( String.Format("Deleting file {0}",filename), String.Format("Are you sure you want to delete file {0}", filename), "Delete file")) { if (IsReadOnly(filename)) { if (!Force && !ShouldContinue( String.Format("File {0} is read-only. Are you sure you want to delete read-only file {0}?", filename), "Delete file"), ref yesToAll, ref noToAll ) { return; } } // delete the object } } } }

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.
See Also

Applies to