HostUtilities.InvokeOnRunspace(PSCommand, Runspace) Method

Definition

Helper method to invoke a PSCommand on a given runspace. This method correctly invokes the command for these runspace cases:

  1. Local runspace. If the local runspace is busy it will invoke as a nested command.
  2. Remote runspace.
  3. Runspace that is stopped in the debugger at a breakpoint.

Error and information streams are ignored and only the command result output is returned.

This method is NOT thread safe. It does not support running commands from different threads on the provided runspace. It assumes the thread invoking this method is the same that runs all other commands on the provided runspace.

public:
 static System::Collections::ObjectModel::Collection<System::Management::Automation::PSObject ^> ^ InvokeOnRunspace(System::Management::Automation::PSCommand ^ command, System::Management::Automation::Runspaces::Runspace ^ runspace);
public static System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> InvokeOnRunspace (System.Management.Automation.PSCommand command, System.Management.Automation.Runspaces.Runspace runspace);
static member InvokeOnRunspace : System.Management.Automation.PSCommand * System.Management.Automation.Runspaces.Runspace -> System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject>
Public Shared Function InvokeOnRunspace (command As PSCommand, runspace As Runspace) As Collection(Of PSObject)

Parameters

command
PSCommand

Command to invoke.

runspace
Runspace

Runspace to invoke the command on.

Returns

Collection of command output result objects.

Applies to