PowerShell plays a central role in managing Exchange, both Microsoft 365 and on premises. Instead of running commands and scripts on the server console, you can install the Exchange module on a workstation. On premises, this requires a little more effort.

Microsoft currently provides version 2 of the PowerShell module for Exchange Online. The installation there works as follows.

First, you must check the standard authentication for Windows Remote Management (WinRM) and, if necessary, configure it from a command prompt with administrative rights. To view the current settings, enter this command:

winrm get winrm/config/client/auth

Displaying current settings for WinRM authentication

By default, the value for Basic should already be true. If this is not the case, you can change it using this:

winrm set winrm/config/client/auth @{Basic="true"}

If this setting is not configured as described, the following error message will appear when you try to connect to Exchange Online:

"The WinRM client cannot process the request. Basic authentication is currently disabled in the client configuration. Change the client configuration and try the request again."

Installing the module for Exchange Online

To be able to execute scripts, if not already done, you have to loosen the execution policy:

Set-ExecutionPolicy RemoteSigned

Next, execute the following command from a PowerShell console with administrative privileges.

Install-Module PowershellGet -Force

After this step, close the PowerShell console and then open it again with elevated privileges. Next, I will install the module ExchangeOnlineManagement:

Install-Module -Name ExchangeOnlineManagement

Installing the ExchangeOnlineManagement PowerShell module

Now you use…

Connect-ExchangeOnline

…to connect to Office 365 in order to send commands.

Connecting to Exchange Online by using the Connect ExchangeOnline cmdlet

Connecting to Exchange Online by using the Connect ExchangeOnline cmdlet

After you log on, the command will print a small table that shows which cmdlets have changed with the new module.

Installing Exchange Management Shell

On premises, the whole task is a bit more complex because PowerShell for Exchange is part of the management tools. These are on the Exchange installation media.

The first step is to enable some optional features:

Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementScriptingTools, IIS-ManagementScriptingTools, IIS-IIS6ManagementCompatibility, IIS-LegacySnapIn, IIS-ManagementConsole, IIS-Metabase, IIS-WebServerManagementTools, IIS-WebServerRole
Enabling optional features required by the Exchange management tools

Enabling optional features required by the Exchange management tools

In addition, you have to ensure that the correct version of the .NET Framework is installed. After that, you need to add the Microsoft Visual C++ 2012 Redistributable before you can start the actual installation.

The Microsoft Visual C++ 2012 Redistributable is another requirement for the management tools

Now you start the installation of the Exchange management tools with this command:

D:\setup /mode:install /role:managementtools /IAcceptExchangeServerLicenseTerms

After executing the setup, you use either the local Exchange PowerShell or the snap-in to administer Exchange.

Setup adds an icon for the Exchange Management Shell to the Start menu

Setup adds an icon for the Exchange Management Shell to the Start menu

Update

From time to time, you must update both the module for Exchange Online and the management shell for a local Exchange. For Exchange Online, enter the following commands for this purpose:

Subscribe to 4sysops newsletter!

Update-Module PowershellGet
Update-Module -Name ExchangeOnlineManagement

For Exchange on premises, current versions come via cumulative updates every quarter.

5 Comments
  1. Tayfun Deger 3 years ago

    fast and beautiful method.

  2. Fadil 3 years ago

    i get trying to run the last command 
    D:\setup : The term 'D:\setup' is not recognized as the name of a cmdlet, function, script file, or operable program. C
    heck 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
    + D:\setup /mode:install /role:managementtools /IAcceptExchangeServerLi …
    + ~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (D:\setup:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException 
     

    • MR 2 years ago

      You need to download the C++ install package and rename it to setup.exe – if you can add it to your D:\ drive or anywhere else that you can reference in the installation

  3. Avi Benemanuel 2 years ago

    I can't thank you more. Searching microsoft documentation for a simple answer sent me on a loop. Your's was just a KISS.

  4. Mike 1 year ago

    Installing the Exchange Management Tools forced me to install using the slightly different command D:\setup /mode:install /role:managementtools /IAcceptExchangeServerLicenseTerms_DiagnosticDataON or D:\setup /mode:install /role:managementtools /IAcceptExchangeServerLicenseTerms_DiagnosticDataOFF so the LicenseTerms were accepted.

Leave a reply

Your email address will not be published.

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account