Condividi tramite


PowerShell.CreateNestedPowerShell Method

Definition

Creates a nested powershell within the current instance. Nested PowerShell is used to do simple operations like checking state of a variable while another command is using the runspace.

Nested PowerShell should be invoked from the same thread as the parent PowerShell invocation thread. So effectively the parent Powershell invocation thread is blocked until nested invoke() operation is complete.

Implement PSHost.EnterNestedPrompt to perform invoke() operation on the nested powershell.

public:
 System::Management::Automation::PowerShell ^ CreateNestedPowerShell();
public System.Management.Automation.PowerShell CreateNestedPowerShell ();
member this.CreateNestedPowerShell : unit -> System.Management.Automation.PowerShell
Public Function CreateNestedPowerShell () As PowerShell

Returns

Exceptions

  1. State of powershell instance is not valid to create a nested powershell instance. Nested PowerShell should be created only for a running powershell instance.

Applies to