How to Quickly Connect to Exchange Online Powershell

Save to My DOJO

How to Quickly Connect to Exchange Online Powershell

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

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

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 administer 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 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

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 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.

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 log in. 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

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.

Altaro Hyper-V Backup
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

Exchange Online PowerShell is a PowerShell module that allows IT admins to manage remote Exchange Online environments with PowerShell. The Exchange Online PowerShell module contains many different PowerShell cmdlets that allows performing specific Exchange Online management and configuration tasks, such as configuring mail flow rules and connectors. It supports modern authentication and also works with multi-factor authentication. This feature allows organizations to extend their multi-factor policies to Exchange Online PowerShell sessions.
To connect to the Exchange Online PowerShell module, you first need to import the module using the Import-Module ExchangeOnlineManagement cmdlet. Then, to connect to Exchange Online Powershell, you run the Connect-ExchangeOnline cmdlet.
PowerShell for Office 365, now Microsoft 365, allows you to manage your environment from the command line and the various services that exist in the Microsoft 365 environment, including using it to connect to Exchange Online Powershell. The first step required to connect to Office 365 or Microsoft is to install the required software. Run this command to install the basic Azure AD module for working with Office 365/Microsoft 365 from the command line, Install-Module -Name AzureAD. After this to connect to Exchange Online Powershell, you install the ExchangeOnlineManagement module mentioned above for the Office 365 connect to Exchange Online PowerShell process Install-Module PowershellGet -Force Update-Module PowershellGet Install-Module -Name ExchangeOnlineManagement
Accessing Microsoft Exchange Online requires IT admins install the required modules in PowerShell and then run the appropriate connect commands. The process to connect to Exchange Online Powershell requires installing the “ExchangeOnlineManagement” module and using the “Connect-ExchangeOnline” cmdlet to connect to their environment. During the connection process, any configured multi-factor authentication details will need to be entered to gain access via PowerShell. The login process looks identical to logging into the Microsoft Azure portal.
Connecting Exchange Online with MFA and PowerShell simply requires the user who is accessing the Exchange Online environment is configured with MFA on their account. During the “Connect-ExchangeOnline” process used to connect to Exchange Online Powershell, the user will be prompted as expected with a GUI dialog box, allowing them to enter their MFA details.
Exchange PowerShell, used to connect to Exchange Online Powershell, is freely available. To get the required module, you simply run the command to install the module, Install-Module ExchangeOnlineManagement. Accept the prompts that follow.

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.