What you need before you start
Exchange Online PowerShell is a command-line tool that lets you manage your Microsoft 365 email accounts, mailboxes, and distribution lists from your computer instead of clicking through the web interface. To connect, you need three things: a Microsoft 365 account with Exchange Online, PowerShell installed on your computer, and the Exchange Online Management module downloaded from Microsoft.
This is different from the regular Outlook or web mail — you are opening a text-based command window and typing instructions that run directly against your email system. Most people never need to do this, but if you manage multiple mailboxes, automate repetitive tasks, or need to change settings that the web interface does not expose, PowerShell is the fastest way.
The process takes about 10 minutes the first time. After that, connecting takes 30 seconds.
Key Takeaways
- You need PowerShell 5.1 or later installed on your computer, which comes built-in on Windows 10 and later, and can be installed on Mac or Linux.
- The Exchange Online Management module must be downloaded once from Microsoft's official repository before you can connect.
- Each time you open PowerShell, you run a single Connect command that asks for your Microsoft 365 username and password.
- If the connection fails, the most common causes are an outdated PowerShell version, a module that did not install correctly, or a Microsoft 365 account that does not have Exchange Online.
Check your PowerShell version
Open PowerShell on your computer. On Windows, press the Windows key, type powershell, and click Windows PowerShell. On Mac or Linux, open Terminal and type pwsh.
At the command prompt, type this exactly and press Enter:
$PSVersionTable.PSVersion
You will see a version number. You need version 5.1 or higher. If you see 5.0 or lower, or if you get an error, you need to update PowerShell before continuing. On Windows, read the latest version from the Microsoft PowerShell GitHub page. On Mac or Linux, follow the installation instructions for your operating system on that same page.
Once you have confirmed your version is 5.1 or higher, leave PowerShell open — you will use it in the next step.
Install the Exchange Online Management module
In the same PowerShell window, type this command and press Enter:
Install-Module -Name ExchangeOnlineManagement -Repository PSGallery -Force
PowerShell will read the module from Microsoft's official repository. This takes one to three minutes depending on your internet speed. You may see a prompt asking if you trust the repository — type Y and press Enter to continue.
When the read finishes, you will see the command prompt again with no error message. That means the module installed successfully. If you see a red error message, the most common cause is that your computer does not have internet access to Microsoft's servers, or your network blocks the read. Check your internet connection and try again.
You only need to do this step once. The module stays on your computer, and you can use it every time you open PowerShell.
Connect to Exchange Online
In PowerShell, type this command and press Enter:
Connect-ExchangeOnline -UserPrincipalName your.email@company.onmicrosoft.com
Replace your.email@company.onmicrosoft.com with the full email address of your Microsoft 365 account. This is usually the email address you use to log in to Outlook or the Microsoft 365 web portal.
PowerShell will open a login window. Enter your Microsoft 365 password and click Sign In. If your organization uses multi-factor authentication, you will see a second prompt asking you to verify your identity — complete that step using the method your organization set up (usually a code from an app or a text message).
When the login succeeds, you will see a message that says you are connected to Exchange Online. The command prompt will return, and you can now type Exchange Online commands.
Test your connection with a straightforward command
To confirm the connection is working, type this command and press Enter:
Get-Mailbox
This command lists all the mailboxes you have permission to see. You should see at least your own mailbox listed with its email address and other details. If you see a list of mailboxes, your connection is working correctly.
If you see an error message instead, the most common causes are: your Microsoft 365 account does not have Exchange Online enabled, your password was entered incorrectly during login, or your organization has restricted PowerShell access. Contact your IT department or Microsoft 365 administrator to confirm your account has the right permissions.
Disconnect when you are finished
When you are done running commands, type this and press Enter:
Disconnect-ExchangeOnline
This closes your connection to Exchange Online. You can close the PowerShell window after this, or leave it open and run the Connect command again later if you need to reconnect.
If you close PowerShell without disconnecting, the connection will close automatically after a few minutes of inactivity. Disconnecting explicitly is cleaner and faster.
What to do if connection fails
If the Connect-ExchangeOnline command does not work, check these things in order. First, confirm your PowerShell version is 5.1 or higher by running $PSVersionTable.PSVersion again. Second, confirm the Exchange Online Management module installed by typing Get-Module -Name ExchangeOnlineManagement — if it does not appear in the list, run the Install-Module command again. Third, confirm your Microsoft 365 account has Exchange Online by logging into the Microsoft 365 admin center and checking that your user account has an Exchange Online license assigned.
If all three of those check out and the connection still fails, the problem is usually on your network or your organization's side. Try connecting from a different network (like a phone hotspot) to see if the issue is your home or office network. If it works on a different network, your firewall or network administrator is blocking the connection. If it fails everywhere, contact your IT department or Microsoft support.
Frequently Asked Questions
Do I need to install the module every time I use PowerShell?
No. You install the module once, and it stays on your computer. Every time you open PowerShell after that, you only need to run the Connect-ExchangeOnline command. The module is already there.
Can I use the same PowerShell window to manage multiple Microsoft 365 accounts?
No. One PowerShell window connects to one account at a time. If you need to manage two different accounts, open a second PowerShell window and connect with the other account's credentials in that window. You can then switch between the two windows.
What if I forget the exact command to connect?
Type Get-Help Connect-ExchangeOnline in PowerShell and press Enter. This shows the full command syntax and all available options. You can also type Get-Help Connect-ExchangeOnline -Examples to see real examples of how to use it.
Is it safe to type my password in PowerShell?
The Connect-ExchangeOnline command does not ask you to type your password in the PowerShell window. Instead, it opens a separate login window where you enter your credentials securely. Your password is never visible in the PowerShell command line itself.
Can I automate this connection so I do not have to log in every time?
Yes, but it requires setting up a service principal or using stored credentials, which is more advanced. For most users, logging in each time you open PowerShell is the standard and safest approach. If you run PowerShell scripts regularly, look into delegated access or app-based authentication in the Microsoft 365 documentation.