Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }