Avatar of Albert Widjaja
Albert Widjaja
Flag for Australia asked on

Unable to load Exchange Server powershell library ?

Folks,

Can anyone please share the trick in how to run the Exchange Server 2010 powershell in PowerGUI powershell IDE ?

Because in my WIndows 8.1 the Powershell version is as follows:

Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.

PS H:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34209
BuildVersion                   6.3.9600.17400
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

Open in new window


and this is the error that I'm receiving in the Console Window:
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.
At line:1 char:258
+ ... t -eq 0 } | %{ Add-PSSnapin $_ }
+                    ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Excha...owerShell.E2010:String) [Add-PSSnapin], PSSnapInException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

Open in new window


Any kind of help and assistance would be greatly appreciated.

Thanks
PowershellExchangeScripting Languages

Avatar of undefined
Last Comment
Albert Widjaja

8/22/2022 - Mon
SreRaj

Hi,

Looks like direct loading of Ex2010 EMS is not supported with 4.0. You may have to establish a remote session to server. Following article has more information on establishing remote session.

https://technet.microsoft.com/en-us/library/dd297932(v=exchg.141).aspx

Following is the discussion on TechNet regarding this.

https://social.technet.microsoft.com/Forums/exchange/en-US/d45f0808-b5fb-469d-8a39-60d1d160c1a0/exchange-2010-pssnapin-exception
Albert Widjaja

ASKER
ok, so how do I execute the PowerShell that I got it opened in my PowerGUI IDE on my laptop.
SreRaj

If you have a PowerShell Script which loads Exchange 2010 PowerShell Snap-in in between, you will have to modify the script so that it establishes a remote PS Session with an Exchange Server and then proceeds with the remaining commands.

This limitation only applies Exchange 2010 PS Snap-in. Other PowerShell commands and scripts will work as it is.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Qlemo

As said above, https://technet.microsoft.com/en-us/library/dd297932(v=exchg.141).aspx describes it well:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<FQDN of Exchange 2010 server>/PowerShell/ -Authentication Kerberos
Import-PSSession $Session

Open in new window

If you can use your current credentials, that is from inside your domain.
Be aware that you are executing anything remote, so you should make sure to filter as much data as possible pre displaying. Object serialization for Remoting consumes a lot of resources.
Albert Widjaja

ASKER
OK which resources here that is consumed ?

My laptop or the exchange servers ?
Once the script finished it should then released the memory right.
Qlemo

All of network, server and client...  But yes, resources are released when finished.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Albert Widjaja

ASKER
Ok, so if I want to use the PowerGUI IDE or the builtin Windows powershell ISE, I need to put the two lines below for every command that I want to execute ?

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<FQDN of Exchange 2010 server>/PowerShell/ -Authentication Kerberos
Import-PSSession $Session

Open in new window


is that correct ?

While the disadvantage of running the command with the first two lines above is that the IDE doesn't do Intellisense or autocomplete.
Qlemo

Correct.
Albert Widjaja

ASKER
ok, one last question to clarify.

I've got 4x Exchange Server VMs running as follows:
All of the Exchange Servers is on 2010 SP3:

HT/CAS: Windows NLB
PRODHTCAS01-VM
PRODHTCAS02-VM

Mailbox: No DAG just stand alone servers.
PRODMBX01-VM
PRODMBX02-VM

so which Exchange server address should I put into the URI http://<FQDN of Exchange 2010 server>/PowerShell ?
should I use the NLB Cas Array name ?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Qlemo

I assume you'll need to provide the CAS array name.
Albert Widjaja

ASKER
somehow it is still doesn't work:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://outlook.domain.com/PowerShell/ -Authentication Kerberos
Import-PSSession $Session

Get-ExchangeDiagnosticInfo

Open in new window


This is the error:
New-PSSession : [outlook.domain.com] Connecting to remote server outlook.domain.com failed with the following error message : WinRM cannot process the request. The following
error occurred while using Kerberos authentication: The computer outlook.domain.com is unknown to Kerberos. Verify that the computer exists on the network, that the name
provided is spelled correctly, and that the Kerberos configuration for accessing the computer is correct. The most common Kerberos configuration issue is that an SPN with the
format HTTP/outlook.domain.com is not configured for the target. If Kerberos is not required, specify the Negotiate authentication mechanism and resubmit the operation. For
more information, see the about_Remote_Troubleshooting Help topic.

At C:\Users\Admin\AppData\Local\Temp\fdf89f0b-89ed-4ae2-9443-f0532857151e.ps1:2 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionOpenFailed
Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At C:\Users\Admin\AppData\Local\Temp\fdf89f0b-89ed-4ae2-9443-f0532857151e.ps1:3 char:18
+ Import-PSSession $Session
+                  ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand

The URL outlook.domain.com is the one that I use in the WNLB on the HT/CAS server and also on the Outlook connection.
Qlemo

outlook.domain.com is member of your domain? If not, you will have to use a different authentication than Kerberos.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Albert Widjaja

ASKER
Well, it is a virtual name for the Windows NLB cluster Virtual IP. For load balancing.
Qlemo

Does that answer my question?
Albert Widjaja

ASKER
There is no computer with the name outlook in the domain.com AD console.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Albert Widjaja

ASKER
Thanks !