title: Executing PowerShell command with parameters from C#
body: <p>I try to execute some PowerShell commands with parameters from c#.</p>
  
  <p>This works fine:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (PowerShell PowerShellInstance = PowerShell.Create())
  {
     PowerShellInstance.AddScript("param($param1); Get-ChildItem $param1");
     PowerShellInstance.AddParameter("param1", "C:\\");
  
     Collection&lt;PSObject&gt; PSOutput =  PowerShellInstance.Invoke();
  
     foreach (var item in PSOutput)
     {
        if(item != null)
        {
          Console.WriteLine(item.BaseObject.ToString());
        }
     }
  }
  </code></pre>
  
  <p>But this does not work:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (PowerShell PowerShellInstance = PowerShell.Create())
  {
     PowerShellInstance.AddScript("param($param1); Get-ChildItem $param1");
     PowerShellInstance.AddParameter("param1", "-Path C:\\");
  
     ...
  }
  </code></pre>
  
  <p>Can someone help me to correct the last code. I would like to use the "-Path" parameter and later the "-Exclude" parameter like this in PowerShell:</p>
  
  <pre><code>Get-ChildItem -Path C: -Exclude *.exe
  </code></pre>