Pergunta

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): o Name: Microsoft.Exchange.Management.PowerShell.Admin o PSVersion: 1.0 o 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 o 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?

Foi útil?

Solução

I had a very similar problem when managing Exchange 2007 using a service developed in C#

Make sure not only that your code is compiled to target the x86 platform but also make sure that you have a specific reference to the C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll file in the class which invokes the PowerShell runspace.

Outras dicas

That Snap-In is probably 32 bit only. Recompiling your service to target the x86 platform (if you are hosting PowerShell) or running the 32 bit version of PowerShell.exe directly from C:\Windows\SysWOW64\WindowsPowerShell\v1.0 should clear things up.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top