/// <summary> /// Initializes the underlying PowerShell object after verifying /// if the pipeline is in a state where it can be invoked. /// If invokeAndDisconnect is true then the remote PowerShell /// command will be immediately disconnected after it begins /// running. /// </summary> /// <param name="syncCall">true if called from a sync call</param> /// <param name="invokeAndDisconnect">Invoke and Disconnect</param> private void InitPowerShell(bool syncCall, bool invokeAndDisconnect = false) { if (_commands == null || _commands.Count == 0) { throw PSTraceSource.NewInvalidOperationException( RunspaceStrings.NoCommandInPipeline); } if (_pipelineStateInfo.State != PipelineState.NotStarted) { InvalidPipelineStateException e = new InvalidPipelineStateException ( StringUtil.Format(RunspaceStrings.PipelineReInvokeNotAllowed), _pipelineStateInfo.State, PipelineState.NotStarted ); throw e; } ((RemoteRunspace)_runspace).DoConcurrentCheckAndAddToRunningPipelines(this, syncCall); PSInvocationSettings settings = new PSInvocationSettings(); settings.AddToHistory = _addToHistory; settings.InvokeAndDisconnect = invokeAndDisconnect; _powershell.InitForRemotePipeline(_commands, _inputStream, _outputStream, _errorStream, settings, RedirectShellErrorOutputPipe); _powershell.RemotePowerShell.HostCallReceived += new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(HandleHostCallReceived); }