title: Using C# to execute PowerShell script with command line args using V2 methods
body: <p>I am writing an C# application which will need to execute Powershell scripts with command line arguments and retrieve the output (aka what I would expect to see in the output window of PowerShell ISE - including exception information)</p>
  
  <p>I have found numerous code examples of how to accomplish this task using PowerShell V1 objects. These examples create runspaces, pipelines, etc. (ex <a href="https://stackoverflow.com/questions/527513/execute-powershell-script-from-c-sharp-with-commandline-arguments">Execute PowerShell Script from C# with Commandline Arguments</a>)</p>
  
  <p>I have seen a few scant references to a different way to do this using PowerShell V2. (the top answer here: <a href="https://stackoverflow.com/questions/1233640/capturing-powershell-output-in-c-sharp-after-pipeline-invoke-throws">Capturing Powershell output in C# after Pipeline.Invoke throws</a>) Using V2 seems <strong>much</strong> simpler. No messing around with runspaces, piplines or any of that. Something like this:</p>
  
  <pre><code>PowerShell powerShell = PowerShell.Create();
  
  powerShell.AddScript(script);
  var results = powerShell.Invoke();
  </code></pre>
  
  <p>Are there any good working examples out there of using PowerShell V2 objects to execute scripts from within C# code? Is there any known good documentation of the PowerShell V2 (or even V3) objects and best practices on how to use them? Offical docs from Microsoft like there ought to be? A good book or site which breaks down the System.Management.Automation assembly piece by piece?</p>