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.
|
| 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.
|
| 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.
|
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 (string target);
- target
- String
Name of the target resource being acted upon. This will potentially be displayed to the user.
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.
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 (string target, string action);
- 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)
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.
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 (string verboseDescription, string verboseWarning, string caption);
- 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.
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.
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 (string verboseDescription, string verboseWarning, string caption, out System.Management.Automation.ShouldProcessReason shouldProcessReason);
- 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.
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.