,
Connecting to Exchange Online through PowerShell is useful in several cases, especially for administrators and IT professionals who manage Microsoft 365/Office 365 environments.
The “Connect-ExchangeOnline” module is a PowerShell command line tool that allows Microsoft 365/Office 365 IT professionals to take advantage of all the features of “Exchange Online” and especially those not offered in the Exchange Admin Center.
For example, connecting to Exchange Online via PowerShell allows you to automate administrative tasks, more easily manage users and their mailboxes, create audit reports, customize Microsoft 365 settings according to business needs, and more.
In this article you’ll learn how to install the Exchange Online Management module* and how to connect to Microsoft 365 Exchange Online through PowerShell.
* Note: The Exchange Online PowerShell module uses Modern authentication to connect to all Exchange-related PowerShell environments in Microsoft 365: Exchange Online PowerShell, PowerShell Security and Compliance, and standalone Exchange Online Protection (EOP) PowerShell. For more information about the Exchange Online PowerShell module, see About the Exchange Online PowerShell module.
How to Connect to Office 365 Exchange Online through PowerShell.
Step 1. Install Exchange Online Management module
1. Download and install Microsoft .NET Framework 4.6.2 or later.
2. Open PowerShell As Administrator.
3. Install the Exchange Online Management module using the following command and press “A” when prompted:*
- Install-Module -Name ExchangeOnlineManagement -RequiredVersion 3.1.0
* Note: If after executing the above command you receive the error “Files cannot be loaded because running scripts is disabled on this system…”, give the following command and then run the above command again:
- Set-ExecutionPolicy RemoteSigned
Step 2. Connect to Exchange Online from PowerShell.
To connect to Exchange online:
1. Open PowerShell As Administrator and give the following command:*
- Connect-ExchangeOnline -UserPrincipalName [email protected] -ShowProgress $true
* Note: In the command replace “[email protected]” with your Microsoft 365 Admin username.
2. On the pop-up window that appears type your Exchange admin credentials and click OK.*
* Note. This cmdlet works for accounts with or without multi-factor authentication (MFA) enabled. If you use MFA, open “Multifactor Authenticator” app and authorize the login request.
3. You’re done! After you have completed your tasks, you can disconnect from Exchange Online using this command:
- Disconnect-ExchangeOnline
Useful PowerShell Exchange Online Commands:
Below you’ll find some useful commands for Exchange Online.
Update Exchange Online Module.
To update the Exchange Online Management Module in latest version give the following command and press “Y” (Yes) when prompted:
- Update-Module -Name ExchangeOnlineManagement
————————————————————————————————-
Get a List of All Mailboxes:
To display a list of all user mailboxes in Exchange Online, give this command:
- Get-Mailbox
————————————————————————————————-
Get List of All Users, Emails & Alias.
To display a list of all users in Exchange Online with their Email and Alias, give this command:
- Get-EXOMailbox | Select DisplayName,PrimarySMTPAddress,Alias
——————————————————————————————-
Get Mailbox Info.
To display the Mailbox information for a specific user (e.g. , give this PowerShell command:
That’s it! Let me know if this guide has helped you by leaving your comment about your experience. Please like and share this guide to help others.