PSCommand.AddCommand PSCommand.AddCommand PSCommand.AddCommand Method

Definition

Overloads

AddCommand(Command) AddCommand(Command)

Add a Command element to the current command pipeline.

AddCommand(String) AddCommand(String) 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) AddCommand(String, Boolean) 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) AddCommand(Command)

Add a Command element to the current command pipeline.

public System.Management.Automation.PSCommand AddCommand (System.Management.Automation.Runspaces.Command command);
member this.AddCommand : System.Management.Automation.Runspaces.Command -> System.Management.Automation.PSCommand
Parameters
command
Command Command Command

Command to add.

Returns

A PSCommand instance with command added.

Exceptions

Powershell instance cannot be changed in its current state.

Remarks

This method is not thread-safe.

AddCommand(String) AddCommand(String) 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 (string command);
member this.AddCommand : string -> System.Management.Automation.PSCommand
Public Function AddCommand (command As String) As PSCommand
Parameters
command
String String String

A string representing the command.

Returns

A PSCommand instance with cmdlet added.

Exceptions

Powershell instance cannot be changed in its current state.

Remarks

This method is not thread safe.

AddCommand(String, Boolean) AddCommand(String, Boolean) 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 (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 String String

A string representing cmdlet.

useLocalScope
Boolean Boolean 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.

Remarks

This method is not thread safe.

Applies to