PowerShell.BeginInvoke Method (PSDataCollection)

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)
'Usage
Dim instance As PowerShell
Dim input As PSDataCollection(Of T)
Dim returnValue As IAsyncResult

returnValue = instance.BeginInvoke(input)
public IAsyncResult BeginInvoke<T> (
	PSDataCollection<T> input
)

GenericParameters

T

The type of the objects in the input buffer.

Parameters

input

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

Return Value

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.

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

PSDataCollection<int> input =
    new PSDataCollection<int>();
input.Add(5);
input.Add(3);
input.Add(2);
input.Complete();

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

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

Exception typeCondition
InvalidOperationException

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

ObjectDisposedException

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(Generic PSDataCollection) 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.


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 Preview

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