Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

PowerShell.AddCommand Method

Definition

Namespace:
System.Management.Automation
Assembly:
System.Management.Automation.dll
Package:
Microsoft.PowerShell.5.1.ReferenceAssemblies v1.0.0
Package:
System.Management.Automation v7.4.15
Package:
System.Management.Automation v7.5.6
Package:
System.Management.Automation v7.6.1

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Name Description
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()
 .AddCommand("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()
 .AddCommand("Get-Process", true)
 .AddCommand("Sort-Object", true);

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()
 .AddCommand("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()
 .AddCommand("Get-Process", true)
 .AddCommand("Sort-Object", true);
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