0
내 C# 응용 프로그램에서 powershell 스크립트로 문자열을 전달하려고합니다.C# 매개 변수를 powershell로 전달
내가 오류에 geting 유지 : "A 위치 매개 변수는 인수를 받아들이는 것을 발견 할 수없는 '$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
필자는 powershell 스크립트를 "Param ($ username) Out-Host $ username"으로 변경했으나 오류가 발생했습니다 : " 'serverName'인수를 사용할 수있는 위치 매개 변수를 찾을 수 없습니다." – woolford
"Param ($ username)"을 "Param ($ serverName)"으로 바꾸어보십시오. –
이제 " '$ null'"agin ... 인수를 허용하는 위치 매개 변수를 찾을 수 없습니다 : \ – woolford