0

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." 
Kelly
  • 835
  • 1
  • 15
  • 29
  • When I run "get-pssnapin -registered", it shows the Exchange snapin being for version 1.0 of PowerShell. I'm assuming I need 2.0 but don't know how to get that (someone else added/registered the one for version 1, however that worked). – Kelly Feb 14 '13 at 20:50

1 Answers1

0

The issue was that my web service were created on the Visual Studio Development Server, not a local (or other) server and security/permissions must be tighter. After selecting Properties for my web service project and going to the Web tab, I selected "Use local IIS Web Server" and had a virtual directory created. In the IIS manager, I enabled Windows Authentication for my web service and this fixed the issue!

Kelly
  • 835
  • 1
  • 15
  • 29