/// <summary> /// Connects synchronously to a running command on a remote server. /// The pipeline object must be in the disconnected state. /// </summary> /// <returns>A collection of result objects.</returns> public override Collection <PSObject> Connect() { InitPowerShellForConnect(true); Collection <PSObject> results; try { results = _powershell.Connect(); } catch (InvalidRunspacePoolStateException) { InvalidRunspaceStateException e = new InvalidRunspaceStateException ( StringUtil.Format(RunspaceStrings.RunspaceNotOpenForPipelineConnect, _runspace.RunspaceStateInfo.State.ToString()), _runspace.RunspaceStateInfo.State, RunspaceState.Opened ); throw e; } // PowerShell object will return empty results if it was provided an alternative object to // collect output in. Check to see if the output was collected in a member variable. if (results.Count == 0) { if (_outputCollection != null && _outputCollection.Count > 0) { results = new Collection <PSObject>(_outputCollection); } } return(results); }