title: C# passing an array to a powershell script
body: <p>I'm attempting to run a powershell script from C#. I have no problem passing strings to the script however when I try to pass an array to the powershell script an exception gets thrown.
  Here is the C# code:</p>
  
  <pre><code>string [] test = {"1","2","3","4"};
  
  RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
  Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
  
  runspace.ApartmentState = System.Threading.ApartmentState.STA;
  runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
  
  runspace.Open();
  RunspaceInvoke invoker = new RunspaceInvoke();
  invoker.Invoke("Set-ExecutionPolicy Unrestricted");
  
  Pipeline pipeline = runspace.CreatePipeline();
  Command myCmd = new Command(@"C:\test.ps1");
  CommandParameter param = new CommandParameter("responseCollection", test);
  myCmd.Parameters.Add(param);
  pipeline.Commands.Add(myCmd);
  
  // Execute PowerShell script
  Collection&lt;PSObject&gt; results = pipeline.Invoke();
  </code></pre>
  
  <p>Here is the powershell script:</p>
  
  <pre><code>param([string[]] $reponseCollection)
  $a = $responseCollection[0]
  </code></pre>
  
  <p>Every time this code executes it throws:</p>
  
  <pre><code>Cannot index into a null array.
  </code></pre>
  
  <p>I know that the code to execute the powershell script is correct when passing strings to the powershell script, it has been thoroughly tested.</p>