Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
I’ve developed a windows service developed in Visual Studio 2010 which performs Exchange 2007 administrative tasks and I’m moving it from a 32-bit development server to a 64-bit production server. The service accepts arguments and then invokes PowerShell to execute commands in the Exchange 2007 snap in.

It works correctly in the development environment both in the debugger and in the windows service itself after it’s been installed; unfortunately, when I copied the project to the new Windows 2008 R2 64-bit server and built it I can only get the service to work in the VS2010 debugger. When installed as a windows service on the 64-bit server the service consistently fails with a message from the PowerShell component of the code which reads:
"No snap-ins have been registered for Windows PowerShell version 2"

The C# code fails on a specific line when the PowerShell instance is invoked:
RunspaceConfiguration rc;
PSSnapInInfo info = rc.AddPSSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out warning);

As I mentioned, the code will work so long as I run it in the VS2010 debugger.

To try and fix this I’ve tried Googling the error and come up with many other people having this problem but no-one having a definitive answer to it. Following some of the leads left in some of these postings I’ve tried these things:
  • I have removed and re-installed the Exchange 2007 management tools

  • I have done a “Get-PSSnapin” from the Exchange Management Shell PowerShell prompt (and got back a listing for the Exchange admin tools that looks like this – the version says that it’s for PSVersion 1.0 rather than 2.0 but, since things work in my VS2010 debugger, I thought that the psversion was not what was causing the problem):


  • Name: Microsoft.Exchange.Management.PowerShell.Admin
    • PSVersion: 1.0

    • Description: Admin Tasks for the Exchange Server

    • I’ve tried registering the snap-in using INSTALLUTIL under the C:\Windows\Microsoft.NET\Framework64\v2.0.50727 as
      Installutil c:\program files\microsoft\exchange server\bin\microsoft.exchange.management.dll



But I’m still stuck running the code in the debugger until I can get it working as a service.

From the tenor of the messages I’ve read about this this is a problem that a lot of people have had but no-one’s been able to completely fix as yet. Can anyone offer any help?
Posted
Updated 11-Aug-11 8:21am
v2

1 solution

Try registering the snap-in using C:\Windows\Microsoft.NET\Framework\v2.0.50727
InstallUtil c:\program files\microsoft\exchange server\bin\microsoft.exchange.powershell.Configuration.dll

Note the difference is in using 32bit version of InstallUtil
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900