Connect to Exchange Online with PowerShell (MFA Support)

by Robert Allen

In this guide, you will learn how to connect to exchange online with PowerShell.

These steps will work MFA or non enable MFA accounts.

I will also show you some useful commands for getting mailbox details and reports.

Let’s jump right in.

Step 1: Install Exchange Online PowerShell Module

To manage exchange online with PowerShell you need to install the Exchange Online V2 Module. Run this command to install the module. This will install from the PSGallery

Install-Module -Name ExchangeOnlineManagement

To verify the module is installed run this command. This command will list all the installed modules on your computer. Look for ExchangeOnlineManagement.

Get-Module -ListAvailable

Step 2: Connect to Exchange Online with PowerShell

Now that the module is installed we can move forward with connecting to Exchange Online. Use the command below to connect to exchange online. This command uses modern authentication and works for MFA or non enable MFA accounts.

Connect-ExchangeOnline

When you run the command you will get prompted to authenticate. If you have MFA enabled it will automatically prompt you to approve the authentication request.

That is it. You should now be connected to Exchange Online. To very you are connected you can run this command. Change Identity to the email address of the account you want to check

Get-EXOMailbox -Identity USER-EMAIL-ADDRESS

Step 3: List ExchangeOnline Module Commands

This step is optional but if you want to list all the functions and commands available in the exchange online module run this command

Get-Command -Module ExchangeOnlineManagement

Exchange Online PowerShell Command Examples

Here are some commands I find useful for exchange online.

Get all Mailboxes

Get-ExoMailbox -ResultSize Unlimited

Get Single User Mailbox Size

Change identify to users name or email address

Get-ExoMailboxStatistics -Identity robert@activedirectorypro.com |select DisplayName,TotalItemSize

Get all Users Mailbox Size

Get-ExoMailbox -ResultSize Unlimited | Get-MailboxStatistics | select DisplayName,TotalItemSize

List Shared Mailboxes

Get-ExoMailbox –ResultSize Unlimited –RecipientTypeDetails SharedMailbox

List Mailboxes that have a forwarding address configured

Get-ExoMailbox -ResultSize Unlimited| where {$_.ForwardingAddress -ne $Null} | select DisplayName,ForwardingAddress

List inactive mailboxes

Get-ExoMailbox -InactiveMailboxOnly | Format-List Name,DistinguishedName,ExchangeGuid,PrimarySmtpAddress

Display quotas for a specific mailbox

Get-ExoMailbox -Identity john.smith@activedirectorypro.com | select *quota*

Display mailboxes that have an archive mailbox

Get-ExoMailbox –ResultSize Unlimited –Archive

I hope you found this guide useful. Post your questions or comments below.

Recommended Tools

  • AD Cleanup Tool - Find stale and inactive user and computer accounts in Active Directory. Export, disable, move or delete the stale accounts to increase security.
  • AD User Creation Tool - Bulk import or update Active Directory user accounts. Add users to groups, import into OUs, set multiple attributes and more.
  • NTFS Permissions Tool - Scan and audit NTFS folder permissions. See which users and groups have access to what.
  • AD Reporting Tool - Over 200 reports on users, computers, groups, OUs and more. Customize reports or create your own reports with the report builder.

Leave a Comment