title: How to Inject an Array Variable into a PowerShell Runspace via New-Variable
body: <p>Assume I have created and opened runspace via</p>
  
  <pre><code>            var rs = RunspaceFactory.CreateRunspace();
              rs.Open();
  </code></pre>
  
  <p>Let's further assume that I want to add a variable into that runspace that is typed as an array by using the New-Variable cmdlet like so:</p>
  
  <pre><code>            // create a pipeline to add the variable into the runspace
              var pipeline = PowerShell.Create();
              // create a command object, add commands and parameters to it...
              var cmd = new PSCommand();
              cmd.AddCommand("New-Variable");
              cmd.AddParameter("Name", "foo");
              cmd.AddParameter("Value", "@()");
              // associate the command with the pipeline and runspace, and then invoke
              pipeline.Commands = cmd;
              pipeline.Runspace = rs;
              pipeline.Invoke();
  </code></pre>
  
  <p>The code works and I get no errors, but the variable 'foo' is not created as an array type. I've tried many different variations on "@()", but none of them have panned out thus far. Ultimately, I think the question boils down to how to properly format the Value argument to New-Variable so that 'foo' will be interpreted as an empty PowerShell array type.</p>
  
  <p>Thanks,</p>
  
  <p>Matt</p>