我正在尝试在 Web 服务中为 Microsoft Exchange 运行一些 Powershell 脚本。下面编写的代码在从控制台应用程序运行时可以正常工作,但是当我将其移动到 Web 服务项目并调用 Web 方法时,它会在调用 AddPSSnapIn 时出错。知道为什么吗?我在 Windows Server 2008 R2 64 位机器上运行它。目标平台已从任何 CPU 更改为 x64,但没有任何运气。
Dim rsConfig As RunspaceConfiguration = RunspaceConfiguration.Create()
Dim snapInException As PSSnapInException = Nothing
Dim info As PSSnapInInfo = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", snapInException) <-- throws an error
' create Powershell runspace and open
Dim MyRunSpace As Runspace = RunspaceFactory.CreateRunspace(rsConfig)
MyRunSpace.Open()
ERROR- System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Management.Automation.PSArgumentException: No snap-ins have been registered for Windows PowerShell version 2."