我需要使用.Net-3.5来实现这一点。
我在我的项目中引用了所需的DLL:
[

]
using System.Management.Automation;
using System.Management.Automation.Runspaces;但是每当我尝试使用WSManConnectionInfo时,例如这里
WSManConnectionInfo connectionInfo = new WSManConnectionInfo();
connectionInfo.ComputerName = machineAddress;
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = runspace;
ps.AddScript("Get-Service");
var results = ps.Invoke();
// Do something with result ...
}
runspace.Close(); 我得到一个“无法找到类型”错误:
The type or namespace 'WSManConnectionInfo' could not be foun (are you missing a using directive or assembly reference?)
我试图远程进入服务器上的PowerShell会话(从客户端机器上本地运行的应用程序),然后该应用程序可以查询此人会话中运行的进程。
根据MSDN,我所需要的只是System.Management.Automation名称空间,我看不到任何关于框架版本限制的内容。我是不是真的很笨,还是微软有着宇宙中最糟糕的文档?
发布于 2016-02-29 15:46:53
我找到了我在找这里的答案。
基本上,我不得不将我的引用从
C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll
至
C:\Program Files(x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll
由于某种原因,这完全解决了我所有的问题-我不知道这两个程序集之间有什么区别,并将非常感谢对此有任何见解。
https://stackoverflow.com/questions/35702441
复制相似问题