我正在尝试在Web服务中为Microsoft Exchange运行一些Powershell脚本。从控制台应用程序运行时,下面编写的代码工作正常,但当我将其移动到Web服务项目并调用Web方法时,它调用AddPSSnapIn时会出错。知道为什么吗?我在Windows Server 2008 R2 64位计算机上运行它。目标平台已从Any 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."
答案 0 :(得分:0)
问题是我的Web服务是在Visual Studio开发服务器上创建的,而不是本地(或其他)服务器,安全/权限必须更严格。为我的Web服务项目选择属性并转到Web选项卡后,我选择了“使用本地IIS Web服务器”并创建了一个虚拟目录。在IIS管理器中,我为我的Web服务启用了Windows身份验证,这解决了这个问题!