Cómo leer el código de salida de PowerShell a través de c #

estoy usandoSystem.Management.Automation.Runspaces para ejecutar scripts de PowerShell. ¿Hay una opción que pueda leer el código de salida de un script dado?

using System.IO;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
using System.Management.Automation;

namespace PowerShell
{
    public class PowerShellExecuter
    {
        public Collection<PSObject> RunPsScript(string psScriptFile)
        {
            string psScript;
            if (File.Exists(psScriptFile))
            {
                psScript = File.ReadAllText(psScriptFile);
            }
            else
            {
                throw new FileNotFoundException("Wrong path for the script file");
            }
            Runspace runSpace = RunspaceFactory.CreateRunspace();
            runSpace.Open();

            RunspaceInvoke runSpaceInvoker = new RunspaceInvoke(runSpace);
            runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");

            Pipeline pipeLine = runSpace.CreatePipeline();
            pipeLine.Commands.AddScript(psScript);
            pipeLine.Commands.Add("Out-String");

            Collection<PSObject> returnObjects = pipeLine.Invoke();
            runSpace.Close();

            return returnObjects;
        }
    }
}

Respuestas a la pregunta(3)

Su respuesta a la pregunta