public static Collection <PSObject> RawExecute(string[] commands) { LastRawResults = null; LastUsedRunspace = InitialSessionState == null? RunspaceFactory.CreateRunspace() : RunspaceFactory.CreateRunspace(InitialSessionState); LastUsedRunspace.Open(); foreach (var command in commands) { using (var pipeline = LastUsedRunspace.CreatePipeline()) { pipeline.Commands.AddScript(command, true); try { LastRawResults = pipeline.Invoke(); } catch (Exception) { LastRawResults = pipeline.Output.ReadToEnd(); throw; } if (pipeline.Error.Count > 0) { throw new MethodInvocationException(String.Join(Environment.NewLine, pipeline.Error.ReadToEnd())); } } } return(LastRawResults); }
public static Collection <PSObject> RawExecute(string[] commands, bool throwOnError = true) { LastRawResults = null; LastRawErrorResults = null; LastUsedRunspace = InitialSessionState == null? RunspaceFactory.CreateRunspace() : RunspaceFactory.CreateRunspace(InitialSessionState); LastUsedRunspace.Open(); return(RawExecuteInLastRunspace(commands, throwOnError)); }