【发布时间】:2015-12-18 23:23:52
【问题描述】:
我想使用 C# 运行以下 PS cmd
Get-SCRunAsAccount -VMMServer VmmserverName -Name proName | Remove-SCRunAsAccount
我尝试了以下程序,但配置文件没有被删除。当我在 Powershell 中运行上述 cmd 时,它可以工作,这意味着 cmd 没有问题。但不确定为什么 RunAsAccount 的对象没有通过 C# 中的管道。
我也尝试过在 c# 中使用管道运行 Get-process | Sort-Object VM 它有效。
帮助我在这里缺少什么
Pipeline pipeline = Runspace.CreatePipeline();
Collection<PSObject> results = null;
string output = null;
Command command = new Command("Get-SCRunAsAccount");
command.Parameters.Add("VMMServer", "VmmserverName");
command.Parameters.Add("Name", "proName");
Command command1 = new Command("Remove-SCRunAsAccount");
pipeline.Commands.Add(command);
pipeline.Commands.Add(command1);
pipeline.Commands.Add("Out-String");
results = pipeline.Invoke();
【问题讨论】:
标签: c# powershell command pipeline