Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell 1

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi,

I am getting the following error when calling the following command from VBScript:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.

There should be nothing wrong with the VBScript code, because all I needed to do was change the line:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
To
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

But here is the VBScript code that calls Powershell:
Code:
strPowerShellExe = "Powershell.exe"

objShell.run strPowerShellExe & " -noexit -command " & chr(34) & "&{" &oFile.ShortPath & " " & strCreateUser & "}" & chr(34),7,True

I am running the above command from a .PS1 script from Windows 7 Enterprise 64-bit. This is for Exchange 2010. It worked with Exchange 2007. (N.B. There is no 32-bit version of EMC 2010)

I have done quite a lot of searching on this and all the articles point to running the wrong version of Powershell. i.e. 32-bit rather than 64-bit.

I have tried calling both versions from the script and neither work.

If I look at the shortcut for the Exchange Management Shell (EMS) it points to:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

This is exactly the same path that powershell.exe runs from in my script.

If I open up powershell from DOS and type in the command:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

it loads the snapin.

Interestingly, the EMS shortcut calls RemoteExchange.ps1. Nowhere in that script does it use the Add-PSSnapin command.

We have upgraded from Exchange 2007 to Exchange 2010 and I am now changing a little tool that creates users using New-Mailbox cmdlet. Obviously, if I can't get the Exchange Snapin to load then I can't run any exchange commands.

I know Exchange 2010 is new, but I am hoping someone out there may spark an idea that'll lead to a solution :)

Many thanks
 
Ok,

It's because the HTA runs in 32-bit mode, therefore the oShell.Run command defaults to the SysWOW64\powershell command.

I created a shortcut to C:\Windows\System32\mshta.exe and appended the path to my HTA. This forces mshta.exe to run in 64-bit mode.

It's caused other issue now, but at least it loads the Exchange 2010 snapin.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top