title: Invoking PowerShell Script with Arguments from C#
body: <p>I have a PowerShell script stored in a file. In Windows PowerShell, I execute the script as<br>
  <code>.\MergeDocuments.ps1 "1.docx" "2.docx" "merge.docx"</code></p>
  
  <p>I want to call the script from C#. Currently I am using Process.Start as follows which works perfectly:<br>
  <code>Process.Start(POWERSHELL_PATH, string.Format("-File \"{0}\" {1} {2}", SCRIPT_PATH, string.Join(" ", filesToMerge), outputFilename));</code></p>
  
  <p>I want to run it using <code>Pipeline</code> class, something like the below code but I don't know how to pass the arguments (keep in mind that I don't have named arguments, I am just using $args)</p>
  
  <pre><code>// create Powershell runspace
  Runspace runspace = RunspaceFactory.CreateRunspace();
  runspace.Open();
  
  RunspaceInvoke runSpaceInvoker = new RunspaceInvoke(runspace);
  runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
  
  // create a pipeline and feed it the script text (AddScript method) or use the filePath (Add method)
  Pipeline pipeline = runspace.CreatePipeline();
  Command command = new Command(SCRIPT_PATH);
  command.Parameters.Add("", ""); // I don't have named paremeters
  pipeline.Commands.Add(command);
  
  pipeline.Invoke();
  runspace.Close();
  </code></pre>