How to Connect to Exchange Online in PowerShell?

Explore two simple ways to get this done

by Loredana Harsana
Loredana Harsana
Loredana Harsana
Managing Editor
Loredana is a passionate writer with a keen interest in PC software and technology. She started off writing about mobile phones back when Samsung Galaxy S II was... read more
Reviewed by Alex Serban
Alex Serban
Alex Serban
Windows Server & Networking Expert
After moving away from the corporate work-style, Alex has found rewards in a lifestyle of constant analysis, team coordination and pestering his colleagues. Holding an MCSA Windows Server... read more
Affiliate Disclosure
  • 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
XINSTALL BY CLICKING THE DOWNLOAD FILE
Easily get rid of Windows errors Fortect is a system repair tool that can scan your complete system for damaged or missing OS files and replace them with working versions from its repository automatically. Boost your PC performance in three easy steps:
  1. Download and Install Fortect on your PC.
  2. Launch the tool and Start scanning
  3. Right-click on Repair, and fix it within a few minutes
  • 0 readers have already downloaded Fortect so far this month

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. 

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

Still experiencing issues?

SPONSORED

If the above suggestions have not solved your problem, your computer may experience more severe Windows troubles. We suggest choosing an all-in-one solution like Fortect to fix problems efficiently. After installation, just click the View&Fix button and then press Start Repair.

This article covers:Topics: