Skip to content

Load Exchange Management Shell in PowerShell ISE

In Exchange Server, we can load Exchange Management Shell module in Windows PowerShell ISE. This way, we can run Exchange cmdlets in PowerShell ISE just like we are used to in Exchange Management Shell. But, is there another way to connect to Exchange Server with PowerShell? This article will teach you how to load Exchange Management Shell snapin in PowerShell ISE.

Information

Microsoft PowerShell ISE stands for Integrated Scripting Environment. Why do we like to use Windows PowerShell ISE if it comes to running scripts or cmdlets?

  • Works more comfortable with the editor
  • Shows you the cmdlets as you type
  • Better interface (GUI)

Error when running Exchange cmdlet in PowerShell ISE

If you run an Exchange cmdlet in PowerShell ISE, you will get an error.

PS C:\> Get-Mailbox
Get-Mailbox : The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Mailbox
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

You did get this error because you don’t have Exchange Management Module imported in Windows PowerShell ISE.

Import Exchange Management Module in PowerShell ISE

We want to import the Exchange module in PowerShell ISE on the Exchange Server. We also like to do the same on another server with Exchange Management Tools installed.

To load Exchange snapin in PowerShell ISE, you can run the following cmdlets. Run Get-Mailbox cmdlet to verify that it’s working.

Add Exchange Management snapin Exchange 2010

Run PowerShell ISE as administrator. Add the Microsoft Exchange Management snapin.

PS C:\> Add-PSsnapin Microsoft.Exchange.Management.PowerShell.E2010

Add Exchange Management snapin Exchange 2013/2016/2019

PS C:\> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

PS C:\> Get-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        ex01-2016        Unlimited
Ali Tajran                Ali.Tajran           ex01-2016        Unlimited
Amanda Morgan             Amanda.Morgan        ex01-2016        Unlimited

Without Exchange Management Tools installed

We have a management server, and we want to connect to the Exchange Server with PowerShell ISE. If you open it on another server without Exchange Management Tools installed, it will not work.

PS C:\> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.
At line:1 char:1
+ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Excha...werShell.SnapIn:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

You get the error because you have to install Exchange Management Tools. After that, run the snapin cmdlet to import Exchange Management Tools.

Connect to Exchange Servers with remote PowerShell

The above Exchange snapin cmdlets will work fine. Is there another way to load the Exchange module in PowerShell? Yes, there is.

In three steps, we can create a remote PowerShell connection to Exchange Server:

  1. Enter credentials
  2. Provide required connection settings
  3. Import Exchange cmdlets

You can connect from Exchange Server itself or another server. For example, a Management Server. The good thing is that you can run this without installing Exchange Management Shell on the remote server. But, some cmdlets will not give you the correct output. For example, the Get-ExchangeCertificate cmdlet will not give you all the properties.

We do recommend to install the Exchange Management Tools on any server to administer Exchange Servers.

Run PowerShell ISE as administrator and run Get-ExecutionPolicy cmdlet to check if it’s correctly set. If it’s not set as RemoteSigned, run the second cmdlet.

PS C:\> Get-ExecutionPolicy

PS C:\> Set-ExecutionPolicy RemoteSigned

1. Enter the credentials

PS C:\> $UserCredential = Get-Credential

A prompt will show. Fill in the account UPN with admin privileges.

Load Exchange Management Shell in PowerShell ISE Get-Credential

2. Provide required connection settings

Replace EX01-2016.exoip.local to your Exchange server FQDN. The connectionUri is http and not https.

PS C:\> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EX01-2016.exoip.local/PowerShell/ -Authentication Kerberos -Credential $UserCredential

3. Import Exchange cmdlets

Import the Exchange cmdlets in the Windows PowerShell session so you can administer Exchange.

PS C:\> Import-PSSession $Session -DisableNameChecking

If you get errors when connecting to the PowerShell virtual directory, read Recreate virtual directories in Exchange Server.

Verify it’s working

Run the Get-Mailbox cmdlet and see the results.

PS C:\> Get-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        ex01-2016        Unlimited
Ali Tajran                Ali.Tajran           ex01-2016        Unlimited
Amanda Morgan             Amanda.Morgan        ex01-2016        Unlimited

If you finished with your work, don’t forget to sign off.

PS C:\> Remove-PSSession $Session

You did connect to Exchange Server from another server or from Exchange server itself. This time with remote PowerShell. Did this load Exchange cmdlets in PowerShell ISE for you?

Keep reading: Install Exchange Online PowerShell module »

Conclusion

In this article, you learned how to load Exchange Management Shell in PowerShell ISE. The next time you connect to the Exchange Server, you can connect with remote PowerShell and not load the Exchange snapin. Both ways will work.

It’s best to Install Exchange Management Tools on any server to administer Exchange Servers. After that, import the Exchange snapin in PowerShell ISE. This way, all the Exchange cmdlets are available.

Did you enjoy this article? You may also like Install Exchange Cumulative Update. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 2 Comments

  1. Hi,

    Great post but have issues with some commands that doesn’t work. Is there any way to get all Ex-commandlets to work from ISE on a server that’s not a Ex-server.

    For example:
    ——————————————————————–
    PS C:\Windows\system32> Get-MobileDeviceStatistics -Mailbox User
    Get-MobileDeviceStatistics : Failed to load assembly; Type=Microsoft.Exchange.Assistants.ItemAssistantContextFactory, Assembly=Microsoft.Exchange.Assistants, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3
    856ad364e35
    At line:1 char:1
    + Get-MobileDeviceStatistics -Mailbox sle19
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (LegacyDn: /o=OF…00-000000000000:UserPrincipal) [Get-MobileDeviceStatistics], RegistryAssemblyLoadException
    + FullyQualifiedErrorId : [Server=VM099,RequestId=5c026722-66f1-439d-b941-126c9558031c,TimeStamp=2021-10-20 09:21:37] [FailureCategory=Cmdlet-RegistryAssemblyLoadException] BC79D62E,Microsoft.Exchange.Managem
    ent.Tasks.GetMobileDeviceStatistics
    —————————————————————————–

    Get-Mailbox works fine!

    1. You have two options:

      1. Install Exchange Management Tools on the machine
      2. Connect to Exchange Servers with remote PowerShell (read the article)

      I tried both options on a non-Exchange Server. The “Get-MobileDeviceStatistics -Mailbox -user” command works fine from PowerShell ISE.

Leave a Reply

Your email address will not be published. Required fields are marked *