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:
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
- Description: Admin Tasks for the Exchange Server
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?