Save to My DOJO
PowerShell is an effective and powerful way to achieve administrative tasks that either require some degree of automation or perform actions not available in the Exchange Online administration GUI and connect to Exchange Online Powershell environment easily. 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 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 can connect to Exchange Online PowerShell using modern authentication (allows you to connect to Exchange Online PowerShell MFA), 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. However, each can be used to connect PowerShell to Exchange Online. Most will want to connect to Exchange Online PowerShell without Basic Authentication, using MFA.
How do I connect to Exchange Online PowerShell?
In the following section, we are going to be using Exchange Online PowerShell V2 module, which is vastly more optimized for bulk operations than version one, and also supports more than just Windows PowerShell, however more on other modalities further below to connect to Exchange Online using remote PowerShell
The process to connect to Exchange Online Powershell starts with, well, with PowerShell, however, there are a few options that are beyond old fashioned Windows PowerShell. The Exchange Online PowerShell V2 module (referred to as EXO V2 module) is supported in Windows PowerShell 5.1. If you are using PowerShell 7 on Windows, you need version 2.0.4 or later of the EXO V2 module to connect to Exchange Online Powershell.
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.
Multi Factor Authentication (MFA) secured accounts
PowerShell in a Browser
You read that 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.
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
Choosing PowerShell as Default Language
We can prove that it is indeed PowerShell and not Bash, by typing in:
Get-Help
And pressing Enter
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.
How To Run PowerShell
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 administer Exchange Online using PowerShell.
Once PowerShell is installed, launch a terminal and type:
pwsh
And press enter.
Run PowerShell on MacOS
How do I install the Exchange Online PowerShell Module
Installing the Exchange Online Module is relatively straightforward 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
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
Connect to Exchange Online on MacOS
How do I log into Exchange Online PowerShell
We noted earlier that Exchange Online PowerShell v2 can use 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. So, if you are wondering how I access Microsoft Exchange Online, this is it.
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.
Connecting to Exchange Online 1
The Exchange cmdlets download and install, and I am done.
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.
Connect to Exchange Online PowerShell
Once authentication is successful, we are able to issue a 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 log in. At a PowerShell prompt type in
Connect-ExchangeOnline
And hit Enter
Connect to Exchange Online PowerShell on MacOS – 1
It successfully launches the browser and performs an SSO login:
Connect to Exchange Online PowerShell on MacOS – 2
Connect to Exchange Online PowerShell on MacOS – 3
Review of commands to connect to Exchange Online PowerShell
The following is a review of the PowerShell commands to connect to Exchange Online:
- Install-module ExchangeOnlineManagement
- If you want to limit the scope to the current user: Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser
- To update the module: Update-Module -Name ExchangeOnlineManagement
- Import-module ExchangeOnlineManagement
- Connect-ExchangeOnline
To properly protect your Hyper-V virtual machines, use Altaro VM Backup to securely backup and replicate your virtual machines. We work hard perpetually to give our customers confidence in their Hyper-V backup strategy.
To keep up to date with the latest Hyper-V best practices, become a member of the Altaro DOJO | Hyper-V now (it’s free).
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 straightforward on all platforms and in the case of Azure cloud Shell is simply built in.
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 you connect to Exchange Online Powershell you can administer Exchange Online, irrespective of platform or operating system in a supported manner.
Not a DOJO Member yet?
Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!