C# 如何在托管代码中使用远程Powershell命令?

C# 如何在托管代码中使用远程Powershell命令?,c#,powershell,dynamic,exchange-server-2010,powershell-remoting,C#,Powershell,Dynamic,Exchange Server 2010,Powershell Remoting,,但它既笨重又明显过时 在托管代码中调用远程powershell命令的正确或现代方法是什么 下面的内容让人觉得过于冗长和过时 Runspace myRunSpace = RunspaceFactory.CreateRunspace(); myRunSpace.Open(); Pipeline pipeLine = myRunSpace.CreatePipeline(); Command getCommand = new Command("Get-Command"); pipeLine.Comma

,但它既笨重又明显过时

在托管代码中调用远程powershell命令的正确或现代方法是什么

下面的内容让人觉得过于冗长和过时

Runspace myRunSpace = RunspaceFactory.CreateRunspace();
myRunSpace.Open();
Pipeline pipeLine = myRunSpace.CreatePipeline();
Command getCommand = new Command("Get-Command");
pipeLine.Commands.Add(getCommand);
Command getMember = new Command("Get-Member");
pipeLine.Commands.Add(getMember);
Collection<PSObject> commandResults = pipeLine.Invoke();
Runspace myRunSpace=RunspaceFactory.CreateRunspace();
myRunSpace.Open();
Pipeline Pipeline=myRunSpace.CreatePipeline();
命令getCommand=新命令(“获取命令”);
pipeLine.Commands.Add(getCommand);
命令getMember=新命令(“获取成员”);
pipeLine.Commands.Add(getMember);
Collection commandResults=pipeLine.Invoke();
您看到这个了吗?今年四月的PS v3。看来你是对的;api已经简化-您可以简单地
AddScript
,然后
Invoke