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.
- Firstly, Exchange Server PowerShell (Exchange Management Shell)
- Secondly, Exchange Online PowerShell
- Thirdly, Security & Compliance PowerShell
- 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.
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.
- First of all, type Connect-ExchangeOnline and press Enter. This command will open sing-in window.
- Secondly, in the sign-in window that opens, enter your email & password information and then click Sign in.
- Multi-Factor Authentication (MFA) Only:
- 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-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.
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.
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.