c# app から powershell script に文字列を渡そうとしています。
エラーが発生し続けます:「引数を受け入れる位置パラメーターが見つかり'$null'
ません。どうすればよいですか?
私のC#コード:
public void PowerShell()
{
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
Pipeline pipeline = runspace.CreatePipeline();
String scriptfile = @"c:\test.ps1";
Command myCommand = new Command(scriptfile, false);
CommandParameter testParam = new CommandParameter("username", "serverName");
myCommand.Parameters.Add(testParam);
pipeline.Commands.Add(myCommand);
Collection<PSObject> psObjects;
psObjects = pipeline.Invoke(); <---error- "A positional parameter cannot be found that accepts argument '$null'"
runspace.Close();
}
私のパワーシェルコード:
Out-Host $username