共用方式為


Cmdlet Class

Definition

Defines members and overrides used by Cmdlets. All Cmdlets must derive from Cmdlet.

public ref class Cmdlet abstract : System::Management::Automation::Internal::InternalCommand
public abstract class Cmdlet : System.Management.Automation.Internal.InternalCommand
type Cmdlet = class
    inherit InternalCommand
Public MustInherit Class Cmdlet
Inherits InternalCommand
Inheritance
Derived

Remarks

There are two ways to create a Cmdlet: by deriving from the Cmdlet base class, and by deriving from the PSCmdlet base class. The Cmdlet base class is the primary means by which users create their own Cmdlets. Extending this class provides support for the most common functionality, including object output and record processing. If your Cmdlet requires access to the PowerShell Runtime (for example, variables in the session state, access to the host, or information about the current Cmdlet Providers,) then you should instead derive from the PSCmdlet base class. In both cases, users should first develop and implement an object model to accomplish their task, extending the Cmdlet or PSCmdlet classes only as a thin management layer.

Constructors

Cmdlet()

Initializes the new instance of Cmdlet class.

Properties

CommandOrigin

This property tells you if you were being invoked inside the runspace or if it was an external request.

(Inherited from InternalCommand)
CommandRuntime

Holds the command runtime object for this command. This object controls what actually happens when a write is called.

CommonParameters

Lists the common parameters that are added by the PowerShell engine to any cmdlet that derives from PSCmdlet.

CurrentPSTransaction

Gets an object that surfaces the current PowerShell transaction. When this object is disposed, PowerShell resets the active transaction.

OptionalCommonParameters

Lists the common parameters that are added by the PowerShell engine when a cmdlet defines additional capabilities (SupportsShouldProcess, SupportsTransactions)

Stopping

Is this command stopping?

Methods

BeginProcessing()

When overridden in the derived class, performs initialization of command execution. Default implementation in the base class just returns.

EndProcessing()

When overridden in the derived class, performs clean-up after the command execution. Default implementation in the base class just returns.

GetResourceString(String, String)

Gets the resource string corresponding to baseName and resourceId from the current assembly. You should override this if you require a different behavior.

Invoke()

Invoke this cmdlet object returning a collection of results.

Invoke<T>()

Returns a strongly-typed enumerator for the results of this cmdlet.

ProcessRecord()

When overridden in the derived class, performs execution of the command.

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, 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)

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.

ShouldProcess(String, String, String, ShouldProcessReason)

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)

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)

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)

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.

StopProcessing()

When overridden in the derived class, interrupts currently running code within the command. It should interrupt BeginProcessing, ProcessRecord, and EndProcessing. Default implementation in the base class just returns.

ThrowTerminatingError(ErrorRecord)

Terminate the command and report an error.

TransactionAvailable()

Returns true if a transaction is available and active.

WriteCommandDetail(String)

Write text into pipeline execution log.

WriteDebug(String)

Display debug information.

WriteError(ErrorRecord)

Internal variant: Writes the specified error to the error pipe.

WriteInformation(InformationRecord)

Route information to the user or host.

WriteInformation(Object, String[])

Route information to the user or host.

WriteObject(Object, Boolean)

Writes one or more objects to the output pipe. If the object is a collection and the enumerateCollection flag is true, the objects in the collection will be written individually.

WriteObject(Object)

Writes the object to the output pipe.

WriteProgress(ProgressRecord)

Display progress information.

WriteVerbose(String)

Display verbose information.

WriteWarning(String)

Display warning information.

Applies to

See also