コマンドラインからできます。
.\test.ps1 1
C# からこれを行う場合、どのようにパラメーターを渡すのですか? 私はもう試した
.AddArgument(1)
.AddParameter("p", 1)
そして、.Invoke() で IEnumerable<object> として値を渡そうとしましたが、$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);
}
}
}