Command Class


Updated: April 27, 2016

Applies To: Windows PowerShell

Defines a command that contains a single cmdlet or script. The Command object is used by the PowerShell and Pipeline objects to define a single command.

Namespace:   System.Management.Automation.Runspaces
Assembly:  System.Management.Automation (in System.Management.Automation.dll)


public ref class Command sealed 


Creates a new Command object that contains the command to be run.

System_CAPS_pubmethodCommand(String^, Boolean)

Creates a new Command object that contains a command and a Boolean value that indicates whether the object contains a script.

System_CAPS_pubmethodCommand(String^, Boolean, Boolean)

Creates a new Command object that contains a cmdlet or script to run, plus two Boolean values that indicate whether the object contains a script and whether the local scope should be used when invoking the script.


Gets or sets the command origin for this command. A command origin of 'Runspace' (the default) applies Runspace restrictions to this command. A command origin of 'Internal' does not apply runspace restrictions.


Gets the command name or script of the Command object.


Checks if the current command marks the end of a statement (see PowerShell.AddStatement())


Gets a Boolean value that indicates whether the Command object contains a script.


Gets and sets PipelineResultTypes constants that specify what output streams are merged for previous unclaimed command results.


Gets the parameters for the command.


Gets a Boolean value that indicates whether the Command object should be run in its own local scope.


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)

System_CAPS_pubmethodMergeMyResults(PipelineResultTypes, PipelineResultTypes)

Merges the results that this Command writes to one stream (such as its Error stream) with the results of another stream (such as the Output stream).


Generates a string representation of the current Command object.(Overrides Object::ToString().)

The Command object can be used in two ways.

Windows PowerShell provides two classes that can define a command. The PSCommand class allows you to build a pipeline of commands (A|B|C) that contain one or more cmdlets and scripts. In contrast, the Command class allows you to specify only a single cmdlet or script in the command.

This class cannot be inherited.

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Community Additions