我准备调用powershell脚本并通过参数。我都希望最终通过一个以上的参数使用C#将变量赋值给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
不回答你的问题这么多的快速评论 - 您是否试图通过.NET与本地ADSI商店进行交互? http://stackoverflow.com/questions/1640022/adsi-library-control-for-net – 2012-08-07 16:13:13
没有从来没有经历过的,但由于 – 2012-08-07 16:18:13