Environment:
Server 2008 R2
Exchange 2010
Description:
We had the following snippet in a script that ran fine under PS 2 when launched from a shortcut with the command: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe-NoExit -File "C:\scripts\CreateUsersandEmails\createusersfromprompt.ps1"
Write-Host "Loading AD plugin..." Import-Module ActiveDirectory Write-Host "Loading Exchange plugin..." Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
However, after upgrading to PS 4, that same snippet threw the error:
"Add-PSSnapin : Cannot load Windows Powershell snap-in Microsoft.Exchange.Management.PowerShell.E2010 because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory .Globals' threw an exception.
After messing around with it a little, I discovered the quick solution was to swap the load order:
Write-Host "Loading Exchange plugin..." Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 Write-Host "Loading AD plugin..." Import-Module ActiveDirectory
Can anyone replicate this issue?