我想调用一个powershell脚本并传递一个参数。我都非常想最终传递一个以上的参数
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
Pipeline pipeline = runspace.CreatePipeline();
String scriptfile = "..\\..\\Resources\\new group.ps1";
Command myCommand = new Command(scriptfile, false);
CommandParameter testParam = new CommandParameter("test3");
myCommand.Parameters.Add(testParam);
pipeline.Commands.Add(myCommand);
Collection<PSObject> psObjects;
psObjects = pipeline.Invoke();
runspace.Close();
问题似乎是……好吧,什么也没发生。这是如何正确分配变量?提供测试powershell脚本
# creates group
net localgroup $username /Add
# makes folder
#mkdir $path