PowerShell.RunspacePool Property
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
Gets and sets the runspace pool used by the PowerShell object. A runspace from this pool is used whenever the PowerShell object pipeline is invoked. This property is introduced in Windows PowerShell 2.0.
Namespace: System.Management.Automation
Assembly: System.Management.Automation (in System.Management.Automation)
Namespace: System.Management.Automation
Assembly: System.Management.Automation (in System.Management.Automation)
/** @property */ public RunspacePool get_RunspacePool () /** @property */ public void set_RunspacePool (RunspacePool value)
public function get RunspacePool () : RunspacePool public function set RunspacePool (value : RunspacePool)
Property Value
Returns a RunspacePool object that defines the runspaces of the pool. This property can be set to null, in which case a new runspace is created whenever the pipeline is invoked.This example shows how to create a runspace pool object that has a single runspace, open the runspace, use a PowerShell object to run commands in the runspace, how to close the runspace, and then how to dispose the runspace pool object to free resources.
using (RunspacePool rsp = RunspaceFactory.CreateRunspacePool()) { rsp.Open(); // Create a PowerShell object to run the following command. // get-process wmi* PowerShell gpc = PowerShell.Create(); // Specify the runspace to use and add commands. gpc.RunspacePool = rsp; gpc.AddCommand("Get-Process").AddArgument("wmi*"); // Invoke the command asynchronously. IAsyncResult gpcAsyncResult = gpc.BeginInvoke(); // Get the results of running the command. PSDataCollection<PSObject> gpcOutput = gpc.EndInvoke(gpcAsyncResult); // Process the output. Console.WriteLine("The output from running the command: get-process wmi*"); for (int i= 0; i < gpcOutput.Count; i++) { Console.WriteLine( "Process Name: {0} Process Id: {1}", gpcOutput[i].Properties["ProcessName"].Value, gpcOutput[i].Properties["Id"].Value); }
| Exception type | Condition |
|---|---|
| InvalidPowerShellStateException |
The PowerShell object cannot be changed in its current state. |
| ObjectDisposedException |
The PowerShell object is disposed. |
When concurrently using multiple runspaces from a runspace pool, you must create a new PowerShell object for each runspace that you are using.
This property and the Runspace property are mutually exclusive; setting one of them resets the other to null.
To invoke the pipeline synchronously, call the Invoke method. To invoke the pipeline asynchronously, call the BeginInvoke method.
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
Windows Developer Preview, Windows Server Developer PreviewSend comments about this topic to Microsoft.