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
To fix various PC problems, we recommend Restoro PC Repair Tool:
This software will repair common computer errors, protect you from file loss, malware, hardware failure and optimize your PC for maximum performance. Fix PC issues and remove viruses now in 3 easy steps:

  1. Download Restoro PC Repair Tool that comes with Patented Technologies (patent available here).
  2. Click Start Scan to find Windows issues that could be causing PC problems.
  3. Click Repair All to fix issues affecting your computer's security and performance
  • Restoro has been downloaded by 0 readers 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 having issues? Fix them with this tool:

SPONSORED

If the advices above haven't solved your issue, your PC may experience deeper Windows problems. We recommend downloading this PC Repair tool (rated Great on TrustPilot.com) to easily address them. After installation, simply click the Start Scan button and then press on Repair All.

This article covers:Topics: