title: How to pass a parameter from C# to a PowerShell script file?
body: <p>From the command line I can do.</p>
  
  <pre><code>.\test.ps1 1
  </code></pre>
  
  <p>How do I pass the parameter when doing this from C#?
  I've tried</p>
  
  <pre><code>   .AddArgument(1)
     .AddParameter("p", 1)
  </code></pre>
  
  <p>And I have tried passing values in as IEnumerable&lt;object> in the .Invoke() but $p does not get the value.</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      using System;
      using System.Linq;
      using System.Management.Automation;
  
      class Program
      {
          static void Main()
          {
              // Contents of ps1 file
              //  param($p)
              //  "Hello World ${p}"
  
              var script = @".\test.ps1";
  
              PowerShell
                  .Create()
                  .AddScript(script)
                  .Invoke().ToList()
                  .ForEach(Console.WriteLine);
          }
      }
  }
  </code></pre>