PowerShell.BeginInvoke<T> Method (PSDataCollection<T>)


Updated: April 27, 2016

Applies To: Windows PowerShell

Asynchronously runs the commands of the PowerShell object pipeline by using a specified input buffer for the first command of the pipeline. This method is introduced in Windows PowerShell 2.0.

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

public IAsyncResult BeginInvoke<T>(
	PSDataCollection<T> input


Type: System.Management.Automation.PSDataCollection<T>

A PSDataCollection<T> of type parameter T that contains the input data for the first command of the pipeline.

Return Value

Type: System.IAsyncResult

An IAsyncResult interface that represents the status of the asynchronous operation. The EndInvoke method uses this interface to determine when to return the results of the operation.

Type Parameters


The type of the objects in the input buffer.

Exception Condition

Cannot invoke the pipeline because the operation is already started, or there are no commands in the pipeline.


The PowerShell object is disposed.

When providing input data, the input buffer must be closed before the asynchronous invocation of the pipeline is complete. To close the input buffer, the caller of the BeginInvoke<T> method must call the Complete method after all input is written to the buffer. If you do not call the Complete method, Windows PowerShell will continue to wait for input data and not invoke the pipeline. If you observe that the invocation is not doing anything, this might be the reason.

The following example asynchronously runs the Sort-Object cmdlet based on input from a supplied input buffer.

// Create the data to be sorted by the Sort-Object cmdlet.
PSDataCollection<int> input =
    new PSDataCollection<int>();

// Create an IAsyncResult object and call the
// BeginInvoke method to start running the 
// command pipeline asynchronously.
IAsyncResult async = ps.BeginInvoke<int>(input);

// Using the PowerShell.Invoke method, run the command
// pipeline using the default runspace.
foreach (PSObject result in ps.EndInvoke(async))
} // End foreach.

Return to top

Community Additions