Delen via


PowerShell.AddCommand Method

Definition

Overloads

AddCommand(CommandInfo)

CommandInfo object for the command to add.

AddCommand(String)

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

PowerShell shell = PowerShell.Create("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",

PowerShell shell = PowerShell.Create("get-process").AddCommand("sort-object");

AddCommand(CommandInfo)

CommandInfo object for the command to add.

public:
 System::Management::Automation::PowerShell ^ AddCommand(System::Management::Automation::CommandInfo ^ commandInfo);
public System.Management.Automation.PowerShell AddCommand (System.Management.Automation.CommandInfo commandInfo);
member this.AddCommand : System.Management.Automation.CommandInfo -> System.Management.Automation.PowerShell
Public Function AddCommand (commandInfo As CommandInfo) As PowerShell

Parameters

commandInfo
CommandInfo

The CommandInfo object for the command to add.

Returns

A PSCommand instance with the command added.

Exceptions

command is null.

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread-safe.

Applies to

AddCommand(String)

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

PowerShell shell = PowerShell.Create("get-process").AddCommand("sort-object");
public:
 System::Management::Automation::PowerShell ^ AddCommand(System::String ^ cmdlet);
public System.Management.Automation.PowerShell AddCommand (string cmdlet);
member this.AddCommand : string -> System.Management.Automation.PowerShell
Public Function AddCommand (cmdlet As String) As PowerShell

Parameters

cmdlet
String

A string representing cmdlet.

Returns

A PowerShell instance with cmdlet added.

Exceptions

cmdlet is null.

Powershell instance cannot be changed in its current state.

Object is disposed.

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

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

Parameters

cmdlet
String

A string representing cmdlet.

useLocalScope
Boolean

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

Returns

A PowerShell instance with cmdlet added.

Exceptions

cmdlet is null.

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread safe.

Applies to