How to Connect to Exchange Online in PowerShell

Explore two simple ways to get this done

Reading time icon 3 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

Key notes

  • Batch-processing using PowerShell simplifies some of our administration work.
  • This guide will discuss step-by-step instructions to connect Exchange Online in PowerShell.
connect to exchange online powershell

To perform PowerShell cmdlets to execute some operations in the Exchange Online environment, it is essential to connect Exchange Online in PowerShell.

Here in this blog, we have mentioned two different methods with step-by-step instructions to get it done. Let’s get started! 

How do I connect to Exchange Online in PowerShell?

Before moving to the detailed steps, make sure you perform these preparatory checks: 

  • You must have PowerShell on Windows 7 SP1 or more recent desktop Windows versions and Windows Server 2008 R2 SP1 or newer server Windows versions.
  • The latest version of Windows Management Framework 3.0, 4.0, or 5.1.
  • .NET Framework 4.5 or above Installed.
  • Stable internet connection with TCP port 80 opened to connect from local machine to host.
  • You must have access to Exchange Online PowerShell enabled for the existing user. 

1. Connect to Exchange Online in PowerShell – Classic way

  1. Press the Windows key, type PowerShell, and click Run as administrator.Powershell -connect to exchange online powershell
  2. Copy and paste the following command and press Enter: Set-ExecutionPolicy RemoteSignedAdmin Powershell - Set-ExecutionPolicy RemoteSigned
  3. Type Y when prompted.
  4. Type the following command and press Enter: $UserCredential = Get-Credential
  5. You will get a pop-up to enter your username and password. Input the credentials and press OK.
  6. Input the following commands one by one and press Enter after every command: $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")'

2. Connect to Exchange Online in PowerShell – Alternative method

2.1 Install Exchange Online PowerShell module

  1. Press the Windows key, type PowerShell, and click Run as administrator.
  2. To check if the Exchange Online PowerShell module is already installed, type the below-mentioned cmdlet and press Enter: Get-Module -ListAvailable -Name ExchangeOnlineManagementWindowsTerminal - Get-Module -ListAvailable -Name ExchangeOnlineManagement
  3. If it is not installed, copy and paste the following command and press Enter: Install-Module -Name ExchangeOnlineManagement -ForceWindowsTerminal - Install-Module -Name ExchangeOnlineManagement -Forceconnect to exchange online powershell
  4. Input the following command and press Enter if you have an outdated version installed: Update-Module ExchangeOnlineManagement

2.2 Connect to Exchange Online PowerShell

  1. Now, to connect your Microsoft 365 Exchange Online with the Connect-ExchangeOnline cmdlet, type the following commands and press Enter after every command: #Connect to Exchange Online Connect-ExchangeOnlineExchange Online - connect to exchange online powershell
  2. Enter the credentials on the authentication pop-up window and establish the connectivity.

2.3 Disconnect the Exchange Online PowerShell session

  1. Press the Windows key, type PowerShell, and click Run as administrator.Powershell -connect to exchange online powershell
  2. Copy and paste the following commands and press Enter after every command: #Disconnect Exchange Online Disconnect-ExchangeOnline -Confirm:$FalseDisconnect Exchange -connect to exchange online powershell

So, these are the simplest ways to connect to Exchange Online in Powershell. Try any of them, create a remote session, provide a connection setting, or import PowerShell cmdlets smoothly. 

Connect to Exchange Online can also help you set up DKIM for Microsoft 365 for your domain; read this guide to learn more.

Please let us know in the comments section below if you have any questions or concerns.

More about the topics: Microsoft Exchange