Windows desktop applications
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PowerShell.Commands Property


Updated: April 27, 2016

Applies To: Windows PowerShell

Gets or sets the commands of the pipeline invoked by the PowerShell object. This property is introduced in Windows PowerShell 2.0.

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

public PSCommand Commands { get; set; }

Property Value

Type: System.Management.Automation.PSCommand

A PSCommand object that contains the cmdlets and scripts that are run when the pipeline is invoked.

When this property is set, the PowerShell object makes a copy of the PSCommand that is used when invoking the pipeline. Any changes to the original PSCommand are not reflected in the copy maintained by the PowerShell object.

This property is used to set the pipeline when the commands are predefined by using a PSCommand object.

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

The following example shows how to specify a predefined pipeline and invoke the pipeline synchronously.

// Using the PowerShell object, set the command
// pipeline and invoke the pipeline synchronously.
PowerShell ps = PowerShell.Create();
ps.Commands = cmd;

foreach (PSObject result in ps.Invoke())
} // End foreach.

Return to top

Community Additions

© 2016 Microsoft