PowerShell is an effective and powerful way to achieve administrative tasks that either require some degree of automation or perform an action that isn’t possible in the Exchange Online administration GUI. Those of us who worked on Exchange 2010, remember how the Exchange MMC would generate PowerShell for us and allowed us to learn as we worked. On-premises versions of Exchange still support Exchange Management Shell, however, this article focuses on how to connect to Exchange Online PowerShell.

This article details how to connect to Exchange Online using PowerShell on three platforms, including browser only, Windows and MacOS. The version of Exchange Online PowerShell is quite important, as in this article we reference Exchange Online PowerShell Version 2, which uses modern authentication, as opposed to Exchange Online PowerShell Version 1 which uses basic authentication and is considerably less secure as a result with basic authentication as the only available authentication method.

How do I connect Exchange Online to PowerShell?

In the following section, we are going to be using Exchange Online PowerShell V2 module, which is vastly more optimised for bulk operations than version one, and also supports more than just Windows PowerShell, however more on other modalities further below.

Connecting Exchange Online to PowerShell starts with, well, with PowerShell, however, there are a few options that are beyond old fashioned Windows PowerShell.

Exchange Online PowerShell Version 2 requires PowerShell 7, with specific support for Cloud Shell, Windows, MacOS and Linux.

PowerShell 7 uses browser-based single sign-on (SSO) as the default authentication method, which allows us to take advantage of Multi Factor Authentication (MFA) secured accounts.

PowerShell in a Browser

You read right, you can launch PowerShell from any modern browser and be connected to Office 365 and Azure using Azure Cloud Shell. What’s even more exciting is that Azure Cloud Shell is natively integrated with the Office 365 Admin Console, allowing you to break out into a PowerShell Console as required.

Browse to https://admin.microsoft.com , login and notice the icon for Cloud Shell on the top right-hand corner.

PowerShell in a browser

How to launch Cloud Shell

Clicking on the icon causes Cloud Shell to launch and allows you to choose your command line language of choice. Since we are working with PowerShell, we go ahead and choose PowerShell over Bash, if it isn’t our current default language

Powershell not BASH

Choosing PowerShell as Default Language

We can prove that it is indeed PowerShell and not Bash, by typing in:

Get-Help

And pressing Enter

Browser Cloud Shell

Confirming it’s PowerShell

PowerShell in Windows

PowerShell is built into Windows. Launching PowerShell is as easy as clicking start, typing “PowerShell” and choosing to run it as an administrator, since we will be installing the Exchange Online PowerShell module further on.

PowerShell in Windows

How To Run PowerShell

PowerShell Launches and presents as follows:

PowerShell Launches and presents as follows

How PowerShell looks like

PowerShell on MacOS

PowerShell runs on MacOS allowing you to install modules and run cmdlets as required.

First, install PowerShell on your Mac, however read the entire article and understand the implications of using one installation method versus another.

The details are beyond the scope of this article; however the takeaway is that PowerShell runs on your Mac and you’re able to administrate Exchange Online using PowerShell.

Once PowerShell is installed, launch a terminal and type:

pwsh

And press enter.

PowerShell on MacOS

Run PowerShell on MacOS

How do I install the Exchange Online PowerShell Module

Installing the Exchange Online Module is relatively straight forward once we have an instance of PowerShell.

In a Browser – Cloud Shell

Cloud Shell has a massive advantage. Authentication and module installation is done for us, continue reading in the next session to see how to connect the PowerShell instance in Cloud Shell to Exchange Online.

PowerShell on Windows

Run the following commands in order:

Set-ExecutionPolicy RemoteSigned

Install-Module PowershellGet -Force

Update-Module PowershellGet

Install-Module -Name ExchangeOnlineManagement

PowerShell on Windows

Connect to Exchange Online

PowerShell on MacOS

Similar to Windows, however with one less command run the following command in order

Run the following commands in order:

Install-Module PowershellGet -Force

Update-Module PowershellGet

Install-Module -Name ExchangeOnlineManagement -force

PowerShell on MacOS

Connect to Exchange Online on MacOS

How do I log into Exchange Online PowerShell

We noted earlier that Exchange Online PowerShell v2 uses PowerShell 7, which uses browser based single sign-on as the default authentication method. When we invoke the Connect-ExchangeOnline command, it opens the Azure AD login page in your default browser to gather credentials and return the authentication token to the PowerShell session. I am able to specify credentials or use device-based authentication where I may not have a browser or the ability to launch a browser.

PowerShell in a Browser

With Cloud Shell, the prerequisites to install and be able to launch Exchange Online PowerShell are done for us. I’m also authenticated already in my admin session and do not need to log-on to PowerShell again, unless I wish to specify different credentials or manage another organisation.

All I need to do is type:

Connect-EXOPSSession

And hit Enter.

PowerShell in a Browser

Connecting to Exchange Online 1

The Exchange cmdlets download and install, and I am done.

Exchange cmdlets download and install

Connecting to Exchange Online 2

PowerShell on Windows

To recap, we created a PowerShell session in Windows and installed the Exchange Online v2 module. Next we connect to Exchange Online PowerShell by typing in:

ConnectExchangeOnline

And hitting Enter.

PowerShell session in Windows and installed the Exchange Online v2 module

Connect to Exchange Online PowerShell

Once authentication is successful, we are able to issue a Get-Mailbox command to prove that we are connected:

Get-Mailbox command to prove that we are connected

Issue Get-Mailbox command

PowerShell on MacOS

It seems reasonable that just like Cloud-Shell and Windows PowerShell, we will attempt to use the default browser based SSO method to attempt to login. At a PowerShell prompt type in

Connect-ExchangeOnline

And hit Enter

browser based SSO

Connect to Exchange Online PowerShell on MacOS – 1

It successfully launches the browser and performs an SSO login:

SSO login

Connect to Exchange Online PowerShell on MacOS – 2

PowerShell SSO login

Connect to Exchange Online PowerShell on MacOS – 3

Conclusion

Exchange Online PowerShell Version 2 is the current version of the Exchange cmdlets. It runs on PowerShell 7 which is able to leverage modern authentication on multiple platforms, including Azure Cloud Shell, Microsoft Windows and Apple MacOS. Installation is quick and straight forward on all platforms and in the case of Azure cloud Shell is simply built it.

Connecting to Exchange Online is an identical experience on all three platforms, using browser based SSO, which allows us to integrate with Multi Factor Authentication. Once connected we are able to administrate Exchange Online, irrespective of our platform or operating system in a supported manner.

Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

Frequently Asked Questions

You can launch PowerShell from any modern browser and be connected to Office 365 and Azure using Azure Cloud Shell. Browse to https://admin.microsoft.com , login and notice the icon for Cloud Shell on the top right-hand corner.
Once authenticated in the admin session, type "Connect-EXOPSSession" and hit Enter.
Installing the Exchange Online Module is relatively straightforward once we have an instance of PowerShell. Run the following commands in order: Set-ExecutionPolicy RemoteSigned Install-Module PowershellGet -Force Update-Module PowershellGet Install-Module -Name ExchangeOnlineManagement

Leave a comment or ask a question

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

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

Notify me of follow-up replies via email

Yes, I would like to receive new blog posts by email

What is the color of grass?

Please note: If you’re not already a member on the Dojo Forums you will create a new account and receive an activation email.

Related posts