Sdílet prostřednictvím


ICommandRuntime.ShouldProcess Method

Definition

Overloads

ShouldProcess(String)

Called by the cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

ShouldProcess(String, String)

Called by a cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

This variant allows the caller to specify text for both the target resource and the action.

ShouldProcess(String, String, String)

Called by a cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

This variant allows the caller to specify the complete text describing the operation, rather than just the name and action.

ShouldProcess(String, String, String, ShouldProcessReason)

Called by a cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

This variant allows the caller to specify the complete text describing the operation, rather than just the name and action.

ShouldProcess(String)

Called by the cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

public:
 bool ShouldProcess(System::String ^ target);
public:
 bool ShouldProcess(Platform::String ^ target);
bool ShouldProcess(std::wstring const & target);
public bool ShouldProcess (string target);
public bool ShouldProcess (string? target);
abstract member ShouldProcess : string -> bool
Public Function ShouldProcess (target As String) As Boolean

Parameters

target
String

Name of the target resource being acted upon. This will potentially be displayed to the user.

Returns

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

An implementation should prompt the user in an appropriate manner and return true or false. An alternative trivial implementation would be to just return true all the time.

Remarks

A Cmdlet should declare [Cmdlet( SupportsShouldProcess = true )] if-and-only-if it calls ShouldProcess before making changes.

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

ShouldProcess will take into account command-line settings and preference variables in determining what it should return and whether it should prompt the user.

See also

Applies to

ShouldProcess(String, String)

Called by a cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

This variant allows the caller to specify text for both the target resource and the action.

public:
 bool ShouldProcess(System::String ^ target, System::String ^ action);
public:
 bool ShouldProcess(Platform::String ^ target, Platform::String ^ action);
bool ShouldProcess(std::wstring const & target, std::wstring const & action);
public bool ShouldProcess (string target, string action);
public bool ShouldProcess (string? target, string? action);
abstract member ShouldProcess : string * string -> bool
Public Function ShouldProcess (target As String, action As String) As Boolean

Parameters

target
String

Name of the target resource being acted upon. This will potentially be displayed to the user.

action
String

Name of the action which is being performed. This will potentially be displayed to the user. (default is Cmdlet name)

Returns

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

An implementation should prompt the user in an appropriate manner and return true or false. An alternative trivial implementation would be to just return true all the time.

Remarks

A Cmdlet should declare [Cmdlet( SupportsShouldProcess = true )] if-and-only-if it calls ShouldProcess before making changes.

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

ShouldProcess will take into account command-line settings and preference variables in determining what it should return and whether it should prompt the user.

See also

Applies to

ShouldProcess(String, String, String)

Called by a cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

This variant allows the caller to specify the complete text describing the operation, rather than just the name and action.

public:
 bool ShouldProcess(System::String ^ verboseDescription, System::String ^ verboseWarning, System::String ^ caption);
public:
 bool ShouldProcess(Platform::String ^ verboseDescription, Platform::String ^ verboseWarning, Platform::String ^ caption);
bool ShouldProcess(std::wstring const & verboseDescription, std::wstring const & verboseWarning, std::wstring const & caption);
public bool ShouldProcess (string verboseDescription, string verboseWarning, string caption);
public bool ShouldProcess (string? verboseDescription, string? verboseWarning, string? caption);
abstract member ShouldProcess : string * string * string -> bool
Public Function ShouldProcess (verboseDescription As String, verboseWarning As String, caption As String) As Boolean

Parameters

verboseDescription
String

Textual description of the action to be performed. This is what will be displayed to the user for ActionPreference.Continue.

verboseWarning
String

Textual query of whether the action should be performed, usually in the form of a question. This is what will be displayed to the user for ActionPreference.Inquire.

caption
String

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

Returns

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

Remarks

A Cmdlet should declare [Cmdlet( SupportsShouldProcess = true )] if-and-only-if it calls ShouldProcess before making changes.

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

ShouldProcess will take into account command-line settings and preference variables in determining what it should return and whether it should prompt the user.

An implementation should prompt the user in an appropriate manner and return true or false. An alternative trivial implementation would be to just return true all the time.

See also

Applies to

ShouldProcess(String, String, String, ShouldProcessReason)

Called by a cmdlet to confirm the operation with the user. Cmdlets which make changes (e.g. delete files, stop services etc.) should call ShouldProcess to give the user the opportunity to confirm that the operation should actually be performed.

This variant allows the caller to specify the complete text describing the operation, rather than just the name and action.

public:
 bool ShouldProcess(System::String ^ verboseDescription, System::String ^ verboseWarning, System::String ^ caption, [Runtime::InteropServices::Out] System::Management::Automation::ShouldProcessReason % shouldProcessReason);
public bool ShouldProcess (string verboseDescription, string verboseWarning, string caption, out System.Management.Automation.ShouldProcessReason shouldProcessReason);
public bool ShouldProcess (string? verboseDescription, string? verboseWarning, string? caption, out System.Management.Automation.ShouldProcessReason shouldProcessReason);
abstract member ShouldProcess : string * string * string * ShouldProcessReason -> bool
Public Function ShouldProcess (verboseDescription As String, verboseWarning As String, caption As String, ByRef shouldProcessReason As ShouldProcessReason) As Boolean

Parameters

verboseDescription
String

Textual description of the action to be performed. This is what will be displayed to the user for ActionPreference.Continue.

verboseWarning
String

Textual query of whether the action should be performed, usually in the form of a question. This is what will be displayed to the user for ActionPreference.Inquire.

caption
String

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

shouldProcessReason
ShouldProcessReason

Indicates the reason(s) why ShouldProcess returned what it returned. Only the reasons enumerated in ShouldProcessReason are returned.

Returns

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

Remarks

A Cmdlet should declare [Cmdlet( SupportsShouldProcess = true )] if-and-only-if it calls ShouldProcess before making changes.

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

ShouldProcess will take into account command-line settings and preference variables in determining what it should return and whether it should prompt the user.

An implementation should prompt the user in an appropriate manner and return true or false. An alternative trivial implementation would be to just return true all the time.

See also

Applies to