I am trying to run some Powershell scripts for Microsoft Exchange in web services. The code written below works fine when run from a console application but when I move it into a web services project and call the web method, it errors when it calls AddPSSnapIn. Any idea why? I'm running this on a Windows Server 2008 R2 64-bit machine. The target platform has been changed from Any CPU to x64 without any luck.
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."