PowerShell.AddParameter Method (String, Object)

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Adds a parameter and value to the last command added to the pipeline. This method is introduced in Windows PowerShell 2.0.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

public PowerShell AddParameter(
	string parameterName,
	object value
)

Parameters

parameterName
Type: System.String

The name of the parameter to be added.

value
Type: System.Object

The value of the parameter to be added.

Return Value

Type: System.Management.Automation.PowerShell

A PowerShell object with the specified parameter added to the last command of the pipeline.

Exception Condition
ArgumentException

The value of the parameterName parameter is not null, and the length of the name is zero after trimming whitespace.

InvalidPowerShellStateException

The PowerShell object cannot be changed in its current state.

ObjectDisposedException

The PowerShell object is disposed.

To create a pipeline, call the Create method.

To add cmdlets and scripts to the pipeline, call the AddCommand and AddScript methods.

To invoke the pipeline synchronously, call the Invoke method. To invoke the pipeline asynchronously, call the BeginInvoke method.

This method is not thread safe.

The following example shows how to add a named parameter and its value to the last command in the pipeline. In this case, the Name parameter and its value are added to the Get-Process cmdlet.

// Using the PowerShell object, create the 
// command pipeline and add the commands and  
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-Process");
ps.AddParameter("Name", "s*");

Return to top

Community Additions

ADD
Show: