Connect to Exchange Online using PowerShell

Certainly, This post contains instructions for how to connect to Exchange Online using PowerShell with or without MFA. Exchange online PowerShell module uses modern authentication like multi-factor authentication (MFA) for connecting all Exchange-related PowerShell environments in Microsoft 365. Currently, following PowerShell environments are available in Exchange.

  1. Firstly, Exchange Server PowerShell (Exchange Management Shell)
  2. Secondly, Exchange Online PowerShell
  3. Thirdly, Security & Compliance PowerShell
  4. Finally, Exchange Online Protection PowerShell

Exchange Online Management Module

First of all, We need Import-Module ExchangeOnlineManagement Command from ExchangePowerShell Module before connecting to exchange online.

Import-Module ExchangeOnlineManagement Command

Connect to Exchange Online using PowerShell

Namely, I used Connect-ExchangeOnline command to connect Microsoft Exchange Online using PowerShell as shown in image below. Consequently, This command will display any of the new Cmdlets added into the module or will refer old Cmdlets. Meanwhile, you have to follow these steps.

  1. First of all, type Connect-ExchangeOnline and press Enter. This command will open sing-in window.
  2. Secondly, in the sign-in window that opens, enter your email & password information and then click Sign in.
  3. Multi-Factor Authentication (MFA) Only:
    1. Most importantly, you should receive MFA code based on the response option that is configured for your account. MFA code can be a text message, call or the Microsoft Authenticator app on your device.
Connect to Exchange Online using PowerShell

Connect-ExchangeOnline -UserPrincipalName

Further, You can also use further Connect-ExchangeOnline -UserPrincipalName mrizwan@rizwanranjha.com command to use mrizwan@rizwanranjha.com email address directly in the command. In fact, Connect-ExchangeOnline and Connect-ExchangeOnline -UserPrincipalName commands produces the same results.

Connect-ExchangeOnline -UserPrincipalName

Verify Exchange Online PowerShell Connection

Now, We can verify exchange online connection with any exchange command. However, I am using Get-Mailbox -Identity mrizwan to verify the exchange online connection.

Get-Mailbox Command for Single User

Connect Exchange Online Extras

If you face any issue other than access denied, you can use all these commands in sequence to connect exchange only.

##Connect to Exchange Online.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name ExchangeOnlineManagement;
Import-Module ExchangeOnlineManagement;
Connect-ExchangeOnline;

Furthermore, Exchange Online in Microsoft 365 environment is a best hosted email for Business. Therefore, I am writing various practical Exchange online tutorials to help other system administrators to manage it effectively.

Share

You may also like...