PSCommand Constructor

Initializes a new instance of the PSCommand class. This constructor is introduced by Windows PowerShell 2.0.


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

'Usage
Dim instance As New PSCommand

public PSCommand ()
public PSCommand ()
public function PSCommand ()

The following example shows how to predefine a pipeline that contains the Get-Process cmdlet and invoke the pipeline synchronously.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;


namespace HostPS2
{
  class HostPS2
  {
    static void Main(string[] args)
    {
      // Using the PSCommand object, add the cmdlet 
      // to the command pipeline.
      PSCommand cmd = new PSCommand();
                cmd.AddCommand("Get-Process");
      
      // 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())
      {
        Console.WriteLine("{0,-20}{1}",
                result.Members["ProcessName"].Value,
                result.Members["Id"].Value);
      } // End foreach.
    } // End Main.
  } // End HostPs2.
}

This object is used when you want to predefine the commands that will be invoked (synchronously or asynchronously by a PowerShell object. To invoke these commands, set the PowerShell.Commands property and call the Invoke or BeginInvoke methods.


 

Target Platforms

Windows Developer Preview, Windows Server Developer Preview

Send comments about this topic to Microsoft.
Show:
© 2014 Microsoft