Read Time: 6 minutes
Exchange Online is Microsoft’s cloud-based email service and is included in many Microsoft 365 plans. To manage your Exchange Online account easily, you can use the Exchange Admin Center in Office 365. But for more significant changes in multiple accounts, using PowerShell can be more helpful. It lets admins manage mailboxes, configure email settings, inspect domains, and automate Microsoft 365 tasks through command scripts.
So how can you connect Exchange Online to PowerShell? It remains a concern. In this article, we will showcase how to connect Exchange Online to Windows PowerShell using Microsoft’s current Exchange Online Management module, verify the connection, and disconnect safely.
Prerequisites: Connect Exchange Online to Windows PowerShell
Before connecting to Exchange Online with PowerShell, make sure you have:
- A stable and high-speed internet connection.
- A Microsoft 365 account and credentials with required permissions.
- Windows PowerShell or a supported PowerShell environment.
- Access to complete your organization’s sign-in and MFA requirements.
- Permission to install the Exchange Online Management module V3 in your user profile or system.
Important: The New-PSSession command uses Basic authentication, which is retired for Exchange Online remote PowerShell. Even so, it is not suitable for a standard modern Exchange Online connection. So, from now on, you must use Connect-ExchangeOnline from the Exchange Online Management module to connect using modern authentication.
Set of Commands to Connect Exchange Online to Windows PowerShell
Now, here is the set of commands to connect to Exchange Online PowerShell. Run each command carefully to avoid errors and issues:
- From the Start menu, open Windows PowerShell as administrator.
- To check your PowerShell version, run:
- Run the command below to set the Execution Policy (if not already configured)
- Run this command to install the Exchange Online Management module:
- If the module is already installed, check its availability with the command below:
- Import the module by running the command below:
- Replace with your Microsoft 365 admin account and run the command below to connect Exchange Online to PowerShell
- Run this command to verify your domain:
- You can also retrieve a sample of mailboxes:
- When you have finished your administrative work, disconnect from Exchange Online by running the command below:
$PSVersionTable.PSVersion
Note: You generally do not need to run PowerShell as an administrator just to connect to Exchange Online. Installing the module with the CurrentUser scope also avoids requiring administrator privileges in many cases.
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser
If prompted for the NuGet provider or an untrusted repository, type Y and press Enter. You can also run Install-Module -Name ExchangeOnlineManagement -Force -AllowClobber to override this safety check.
Get-Module ExchangeOnlineManagement -ListAvailable
Import-Module ExchangeOnlineManagement
This makes the module’s Exchange Online commands available in the current session.
Connect-ExchangeOnline -UserPrincipalName YourAdmin@YourDomain.com
A Microsoft sign-in window will appear. Enter your admin account credentials and complete MFA if your organization requires it. After authentication, PowerShell establishes a connection to Exchange Online.
Get-AcceptedDomain
If the command returns your accepted domains, the connection is working, and your account has permission to access that information.
Get-EXOMailbox -ResultSize 10
This command requires the appropriate mailbox access permissions. If it returns an access error, check your assigned Exchange Online role before assuming the connection itself has failed.
Disconnect-ExchangeOnline -Confirm:$false
Read More: Best Practices for Office 365 Mailbox Management
Recommendation: Backup Microsoft 365 Mailbox Data Before Making Changes
As you now know, with Exchange Online PowerShell, admins manage mailboxes and perform bulk administrative tasks. However, commands that delete mailboxes, remove email items, or modify mailbox data can have adverse impacts if used incorrectly.
So, before making major changes, consider keeping a separate copy of important mailbox data as a safer practice. For this, you can use the Kernel Export Office 365 to PST tool and export mailbox data to PST format for separate storage and recovery purposes.
Common Exchange Online PowerShell Connection Issues
Generally, there are no issues connecting Exchange Online with Windows PowerShell. If you get some kind of error at any step, then you can check the following instructions:
- Connect-ExchangeOnline is not recognized
- Module installation fails
- Sign-in or MFA fails
- Access denied
- A Web Account Manager (WAM) error appears
Solution: Check your internet access, PowerShell version, repository configuration, and organizational installation restrictions.
Solution: Confirm that your account can sign in to Microsoft 365 and complete your organization’s authentication requirements.
Solution: Verify that your account has the Exchange Online permissions required for the command you’re running.
Solution: Run Connect-ExchangeOnline -UserPrincipalName YourAdmin@YourDomain.com -DisableWAM. Use this only as a targeted troubleshooting step, rather than the default connection method.
Read More: How to Troubleshoot Microsoft 365 Connectivity Issues?
Benefits of Connecting Exchange Online to PowerShell
After connecting Exchange Online with PowerShell, you can perform all kinds of tasks, such as message tracing in Exchange Online, deleting user mailboxes in Exchange Online, and other centralized tasks, including:
- Automate recurring Microsoft 365 administrative tasks
- Troubleshoot email administration problems in batch
- Check configurations and other Exchange Online settings
- Manage multiple users and make changes to multiple mailboxes at once
- Get mailbox details and manage mailbox settings, subject to assigned permissions
Connect Exchange Online PowerShell and Protect Data Too
To manage email settings, retrieve mailbox information, and automate supported administrative tasks, admins often prefer to connect Exchange Online to Windows PowerShell. For a standard connection, install the Exchange Online Management module, run Connect-ExchangeOnline, sign in, and verify access with an Exchange Online command. When the task is over, end the connection immediately.
Also, remember not to use New-PSSession and legacy authentication approaches, as they are retired by Microsoft. If you also need a separate backup copy of Microsoft 365 mailbox data, assess your organization’s retention and recovery requirements and choose a backup method effectively.
Frequently Asked Questions
A: Yes. The Exchange Online Management module supports modern authentication and MFA. Sign in when prompted and complete your organization’s verification process.
A: Use Connect-ExchangeOnline -UserPrincipalName YourAdmin@YourDomain.com. Replace the demo address with your original admin account and domain.
A: To check connection status, run Get-AcceptedDomain. If it returns the organization’s accepted domains without an error, the connection works.
A: No. The modern Connect-ExchangeOnline method uses modern authentication.
A: To disconnect from Exchange Online PowerShell, run Disconnect-ExchangeOnline -Confirm:$false.
