且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#在远程计算机上执行Powershell脚本

更新时间:2022-12-22 23:01:14

我认为您缺少PowerShell实例与运行空间的绑定.

I think that you are missing the bind of your PowerShell instance to the runspace.

ps.Runspace = runspace;

看看

Take a look to this for more details.

或者,您也可以创建管道(如此处)使用运行空间并调用命令.

Alternatively, you can create a Pipeline (as explained here) using the runspace and invoke the commands.

Pipeline pipeline = runspace.CreatePipeline("<COMMAND TO EXECUTE REMOTELY>");

var results = pipeline.Invoke();