PowerShell.AddParameter Method

Definition

Overloads

AddParameter(String)

Adds a switch parameter to the last added command. For example, to construct a command string "get-process | sort-object -descending"

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

Add a parameter to the last added command. For example, to construct a command string "get-process | select-object -property name"

PowerShell shell = PowerShell.Create("get-process").
                            AddCommand("select-object").AddParameter("property","name");

AddParameter(String)

Adds a switch parameter to the last added command. For example, to construct a command string "get-process | sort-object -descending"

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

Parameters

parameterName
String

Name of the parameter.

Returns

PowerShell

A PowerShell instance with parameterName added to the parameter list of the last command.

Exceptions

Name is non null and name length is zero after trimming whitespace.

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread safe.

Applies to

AddParameter(String, Object)

Add a parameter to the last added command. For example, to construct a command string "get-process | select-object -property name"

PowerShell shell = PowerShell.Create("get-process").
                            AddCommand("select-object").AddParameter("property","name");
public:
 System::Management::Automation::PowerShell ^ AddParameter(System::String ^ parameterName, System::Object ^ value);
public System.Management.Automation.PowerShell AddParameter (string parameterName, object value);
member this.AddParameter : string * obj -> System.Management.Automation.PowerShell
Public Function AddParameter (parameterName As String, value As Object) As PowerShell

Parameters

parameterName
String

Name of the parameter.

value
Object

Value for the parameter.

Returns

PowerShell

A PowerShell instance with parameterName added to the parameter list of the last command.

Exceptions

Name is non null and name length is zero after trimming whitespace.

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread safe.

Applies to