Share via


PSCommand.AddCommand Method

Definition

Overloads

AddCommand(Command)

Add a Command element to the current command pipeline.

AddCommand(String)

Add a command to construct a command pipeline. For example, to construct a command string "get-process | sort-object",

PSCommand command = new PSCommand("get-process").AddCommand("sort-object");
AddCommand(String, Boolean)

Add a cmdlet to construct a command pipeline. For example, to construct a command string "get-process | sort-object",

PSCommand command = new PSCommand("get-process").AddCommand("sort-object");

AddCommand(Command)

Add a Command element to the current command pipeline.

public:
 System::Management::Automation::PSCommand ^ AddCommand(System::Management::Automation::Runspaces::Command ^ command);
public System.Management.Automation.PSCommand AddCommand (System.Management.Automation.Runspaces.Command command);
member this.AddCommand : System.Management.Automation.Runspaces.Command -> System.Management.Automation.PSCommand
Public Function AddCommand (command As Command) As PSCommand

Parameters

command
Command

Command to add.

Returns

A PSCommand instance with command added.

Exceptions

command is null.

Powershell instance cannot be changed in its current state.

Remarks

This method is not thread-safe.

Applies to

AddCommand(String)

Add a command to construct a command pipeline. For example, to construct a command string "get-process | sort-object",

PSCommand command = new PSCommand("get-process").AddCommand("sort-object");
public:
 System::Management::Automation::PSCommand ^ AddCommand(System::String ^ command);
public System.Management.Automation.PSCommand AddCommand (string command);
member this.AddCommand : string -> System.Management.Automation.PSCommand
Public Function AddCommand (command As String) As PSCommand

Parameters

command
String

A string representing the command.

Returns

A PSCommand instance with command added.

Exceptions

Powershell instance cannot be changed in its current state.

cmdlet is null.

Remarks

This method is not thread safe.

Applies to

AddCommand(String, Boolean)

Add a cmdlet to construct a command pipeline. For example, to construct a command string "get-process | sort-object",

PSCommand command = new PSCommand("get-process").AddCommand("sort-object");
public:
 System::Management::Automation::PSCommand ^ AddCommand(System::String ^ cmdlet, bool useLocalScope);
public System.Management.Automation.PSCommand AddCommand (string cmdlet, bool useLocalScope);
member this.AddCommand : string * bool -> System.Management.Automation.PSCommand
Public Function AddCommand (cmdlet As String, useLocalScope As Boolean) As PSCommand

Parameters

cmdlet
String

A string representing cmdlet.

useLocalScope
Boolean

if true local scope is used to run the script command.

Returns

A PSCommand instance with cmdlet added.

Exceptions

Powershell instance cannot be changed in its current state.

cmdlet is null.

Remarks

This method is not thread safe.

Applies to