public IEnumerable <TResult> ExecuteCommandInDebugger <TResult>( PowerShellContext powerShellContext, Runspace currentRunspace, PSCommand psCommand, bool sendOutputToHost, out DebuggerResumeAction?debuggerResumeAction) { debuggerResumeAction = null; PSDataCollection <PSObject> outputCollection = new PSDataCollection <PSObject>(); #if !PowerShellv3 if (sendOutputToHost) { outputCollection.DataAdded += (obj, e) => { for (int i = e.Index; i < outputCollection.Count; i++) { powerShellContext.WriteOutput( outputCollection[i].ToString(), true); } }; } DebuggerCommandResults commandResults = currentRunspace.Debugger.ProcessCommand( psCommand, outputCollection); // Pass along the debugger's resume action if the user's // command caused one to be returned debuggerResumeAction = commandResults.ResumeAction; #endif IEnumerable <TResult> results = null; if (typeof(TResult) != typeof(PSObject)) { results = outputCollection .Select(pso => pso.BaseObject) .Cast <TResult>(); } else { results = outputCollection.Cast <TResult>(); } return(results); }