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);
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.

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 (string cmdlet);
Parameters
cmdlet
String

A string representing cmdlet.

Returns

A PowerShell instance with cmdlet added.

Exceptions

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread safe.

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 (string cmdlet, bool useLocalScope);
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

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread safe.