Как передать параметр из C #в файл сценария PowerShell?

Из командной строки могу.

.\test.ps1 1

Как передать параметр при этом из C #? Я пробовал

  .AddArgument(1)
  .AddParameter("p", 1)

И я пробовал передавать значения как IEnumerable в.Invoke (), но $p не получает значение.

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);
        }
    }
}
11
задан Doug Finke 10 July 2012 в 01:18
поделиться