title: Get Powershell command's output when invoked through code
body: <p>I have written a piece of code (in C#) to execute a Powershell script (specifically Azure PowerShell) using <code>System.Management.Automation</code>. The powershell script basically uploads a vhd in a container on Azure, which shows the upload progress and time elapsed etc when command is manually entered through azure Powershell. Through code everything works fine but i want to get  the result/output of a command (i.e. upload progress, time elapsed), during command execution (i.e. <code>pipeline.invoke();</code>) here is the code:</p>
  
  <pre><code> RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
   Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
   runspace.Open();
   RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
   Pipeline pipeline = runspace.CreatePipeline();
  
   Command myCommand = new Command(scriptPath);
   foreach (var argument in arguments)
   {
       myCommand.Parameters.Add(new CommandParameter(argument.Key, argument.Value));
   }
   pipeline.Commands.Add(myCommand);
  
   var results = pipeline.Invoke(); // i want to get results here (i.e. during command execution) 
   foreach (var psObject in results)
   {
       System.Diagnostics.Debug.Write(psObject.BaseObject.ToString());
   }
  </code></pre>
  
  <p>Please guide if it is possible to retrieve live output from Powershell.</p>