Information
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.

RunspaceFactory Class

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Provides a means to create a single runspace or a pool of runspaces.

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

System.Object
  System.Management.Automation.Runspaces.RunspaceFactory

public static class RunspaceFactory

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCreateOutOfProcessRunspace(TypeTable)

Creates an out-of-process runspace by specifying a type table. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateOutOfProcessRunspace(TypeTable, PowerShellProcessInstance)

Creates an out-of-process runspace by specifying a type table and an instance of a Windows PowerShell process. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace()

Creates a single runspace that uses the default host and runspace configuration.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(InitialSessionState)

Creates a single runspace that uses the default host and specified initial session state information.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(PSHost)

Creates a single runspace that uses a custom host.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(PSHost, InitialSessionState)

Creates a single runspace that uses a custom host and initial session state information.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(PSHost, RunspaceConfiguration)

Creates a single runspace that uses a custom host and runspace configuration information.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(PSHost, RunspaceConnectionInfo)

Creates a single runspace that can be opened on a remote computer. The runspace uses a custom host and connection information.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(RunspaceConfiguration)

Creates a single runspace that uses the default host and specified runspace configuration information.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(RunspaceConnectionInfo)

Creates a single runspace that can be opened on a remote computer. The runspace uses the default host and specified connection information.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(RunspaceConnectionInfo, PSHost, TypeTable)

Creates a single runspace that can be opened on a remote computer. The runspace uses a custom host, connection information, and type table (serialization) information. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(RunspaceConnectionInfo, PSHost, TypeTable, PSPrimitiveDictionary)

Creates a single runspace that can be opened on a remote computer. The runspace uses a custom host, connection information, type table (serialization) information, and endpoint application arguments. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspace(RunspaceConnectionInfo, PSHost, TypeTable, PSPrimitiveDictionary, String)

Creates a runspace using the specified connection info, host name, table type, application arguments, and runspace name. Introduced in Windows PowerShell 4.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool()

Creates a runspace pool that contains a single runspace. This runspace uses the default host and default runspace configuration. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(InitialSessionState)

Creates a pool of runspaces that use the specified initial session state. The initial session state defines the elements, such as cmdlets, scripts, and variables that are accessible within the runspace. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(Int32, Int32)

Creates a pool of runspaces that specifies the minimum and maximum number of opened runspaces for the pool. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(Int32, Int32, InitialSessionState, PSHost)

Creates a runspace pool that specifies minimum and maximum number of opened runspaces, and a custom host and initial session state information that is used by each runspace in the pool. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(Int32, Int32, PSHost)

Creates a pool of runspaces that specifies the minimum and maximum number of opened runspaces for the pool, and a custom host that is used by each runspace. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(Int32, Int32, RunspaceConnectionInfo)

Creates a runspace pool that contains runspaces that can be opened on a remote computer. The runspace pool specifies the minimum number of runspaces that Windows PowerShell maintains open, the maximum number of runspaces in the pool, and the connection information used to connect to a computer. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(Int32, Int32, RunspaceConnectionInfo, PSHost)

Creates a runspace pool that contains runspaces that can be opened on a remote computer. The runspace pool specifies the minimum number of runspaces that Windows PowerShell maintains open, the maximum number of runspaces in the pool, a custom host, and the connection information used to connect to a computer. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(Int32, Int32, RunspaceConnectionInfo, PSHost, TypeTable)

Creates a runspace pool that contains runspaces that can be opened on a remote computer. The runspace pool specifies the minimum number of runspaces that Windows PowerShell maintains open, the maximum number of runspaces in the pool, a custom host, connection information, and type table information used for serialization. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateRunspacePool(Int32, Int32, RunspaceConnectionInfo, PSHost, TypeTable, PSPrimitiveDictionary)

Creates a runspace pool that contains runspaces that can be opened on a remote computer. The runspace pool specifies the minimum number of runspaces that Windows PowerShell maintains open, the maximum number of runspaces in the pool, a custom host, connection information, type table (serialization) information, and endpoint application arguments. This method is introduced in Windows PowerShell 2.0.

A runspace is the operating environment used when invoking the commands of a pipeline. When you create a runspace pool, you create a set of runspaces that have the same features, such as the same initial session state, the same host, and the same information that is used to connect to a computer.

The following are some changes to this class that are introduced in Windows PowerShell 2.0.

This example creates a runspace, opens it synchronously, and then uses the runspace when the pipeline is invoked.

using System;
using System.Management.Automation;           // Windows PowerShell namespace.
using System.Management.Automation.Runspaces; // Windows PowerShell namespace.

namespace HostPS4
{
  class HostPS4
  {
    static void Main(string[] args)
    {

    // Call the CreateRunspace() method to create the 
    // runspace. This call does not specify any 
    // configuration information such as a custom host 
    // or intial session state informtion.
    Runspace rs = RunspaceFactory.CreateRunspace();
    rs.Open();


      // Call the Create() method to create the PowerShell 
      // object, and then specify the runspace and 
      // create the pipeline.
      PowerShell ps = PowerShell.Create();
      ps.Runspace = rs;
      ps.AddCommand("Get-Process").AddArgument("wmi*");

      Console.WriteLine("Process               Id");
      Console.WriteLine("------------------------");


      // Using the PowerShell object, invoke the pipeline 
      // synchronously.
      foreach (PSObject result in ps.Invoke())
      {
        Console.WriteLine("{0,-20}{1}",
                result.Members["ProcessName"].Value,
                result.Members["Id"].Value);
      } // End foreach.
    } // End Main.
  } // End HostPS4.
}

For more examples of creating a single runspace, see Examples of Creating Runspaces

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

Return to top
Show: