PSCommand Class

Defines a pipeline that can be run by a PowerShell object. This class cannot be inherited. This class is introduced in Windows PowerShell 2.0.

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

Dim instance As PSCommand

public sealed class PSCommand
public final class PSCommand
public final class 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();
      // 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.
    } // 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.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Target Platforms

© 2014 Microsoft