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

时间:2014-08-15 00:07:34

标签: c# powershell dynamic exchange-server-2010 powershell-remoting

The linked article describes how to use Exchange Powershell with C#,但它很麻烦,显然已经过时了。

在托管代码中调用远程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();

0 个答案:

没有答案