What you need before you start
To connect to Exchange Online PowerShell, you need three things: a Microsoft 365 account with Exchange Online access, PowerShell installed on your computer, and the Exchange Online Management module. Most people already have the account. The other two are free downloads that take about ten minutes to set up.
PowerShell is a command-line tool built into Windows and Mac that lets you run commands instead of clicking through menus. The Exchange Online Management module is an add-on that gives PowerShell the ability to talk to your Microsoft 365 mailboxes. Without it, PowerShell won't recognize Exchange commands.
If you work in IT or manage mailboxes for your organization, this is the fastest way to do bulk tasks — resetting passwords, checking mailbox sizes, forwarding email, or running reports across hundreds of accounts at once. The graphical interface in the Microsoft 365 admin center can do some of these things, but PowerShell does them faster and in batches.
Key Takeaways
- You need PowerShell 7 or later and the Exchange Online Management module installed before you can connect to Exchange Online.
- The connection command is Connect-ExchangeOnline, which opens a login window where you enter your Microsoft 365 credentials.
- If you get an error about execution policy, run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser first.
- After you connect, you can run commands like Get-Mailbox or Set-Mailbox to manage mailboxes without using the web interface.
- When you are done, type Disconnect-ExchangeOnline to close the connection cleanly.
Install PowerShell 7 on Windows
Open your web browser and go to the PowerShell GitHub releases page (github.com/PowerShell/PowerShell/releases). Look for the latest release — it will be at the top of the page. Find the download link labeled PowerShell-7.x.x-win-x64.msi (the exact version number changes, but the filename pattern stays the same). Click it to download the installer.
Once the file finishes downloading, double-click it to open the installer. Click Next through the setup screens. When you reach the option to add PowerShell to your PATH, make sure that box is checked — this lets you open PowerShell from anywhere on your computer. Click Install, then Finish. Restart your computer after installation completes.
To check that PowerShell installed correctly, press the Windows key, type powershell, and click Windows PowerShell or PowerShell 7 (the newer version). A dark window should open with a prompt that looks like PS C:\Users\YourName>. Type $PSVersionTable.PSVersion and press Enter. You should see version 7.0 or higher. If you see version 5, you opened the old PowerShell — close it and open the new one instead.
Install PowerShell 7 on Mac
Open your web browser and go to github.com/PowerShell/PowerShell/releases. Download the file labeled PowerShell-7.x.x-osx-arm64.pkg if you have an Apple Silicon Mac (M1, M2, or M3), or PowerShell-7.x.x-osx-x64.pkg if you have an Intel Mac. If you are not sure which you have, click the Apple menu, select About This Mac, and look at the Chip line.
Double-click the downloaded file to open the installer. Follow the prompts and enter your password when asked. After installation finishes, open Terminal (press Command+Space, type terminal, and press Enter). Type pwsh and press Enter. PowerShell should open with a prompt that looks like PS /Users/YourName>. Type $PSVersionTable.PSVersion and press Enter to confirm you have version 7 or higher.
Install the Exchange Online Management module
With PowerShell open, type this command exactly and press Enter:
Install-Module -Name ExchangeOnlineManagement -Repository PSGallery -Force -AllowClobber
PowerShell will ask if you trust the repository. Type Y and press Enter. The download and installation will take a few minutes. You will see progress messages as it works. When the prompt returns, the module is installed.
If you get an error that says "execution policy", run this command first:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Type Y when asked to confirm. Then run the module installation command again. This error happens because Windows blocks scripts by default — this command tells PowerShell to allow scripts you download from trusted sources.
Connect to Exchange Online
With PowerShell still open, type this command and press Enter:
Connect-ExchangeOnlineA login window will pop up. Enter your Microsoft 365 email address and password. If your organization uses multi-factor authentication, you will be asked to complete that step — use your phone or authenticator app as usual. After you log in, the window closes and you return to PowerShell.
You should see a message that says something like "The PowerShell session has been successfully configured to use TLS 1.2 for all communications." This means the connection worked. If you see an error instead, check that you installed the Exchange Online Management module correctly by running Get-Module ExchangeOnlineManagement. If nothing appears, the module did not install — try the installation command again.
The connection stays open as long as PowerShell is running. If you close PowerShell or walk away for more than an hour, the connection times out and you have to run Connect-ExchangeOnline again.
Run your first command
Now that you are connected, you can run Exchange commands. Type this command to see a list of all mailboxes in your organization:
Get-MailboxPowerShell will display every mailbox with its name, type, and email address. If you have hundreds of mailboxes, the list will scroll past. To see just one mailbox, type:
Get-Mailbox -Identity "person@company.com"Replace "person@company.com" with the actual email address. PowerShell will show you details about that mailbox — its size, when it was created, whether it is shared or a resource mailbox, and more.
These read-only commands are safe to practice with. If you need to make changes — like setting up forwarding, resetting a password, or changing mailbox permissions — look up the specific command for that task. Most Exchange commands follow the pattern Get- (to look at something), Set- (to change something), or New- (to create something).
Disconnect when you are done
When you finish working, type this command to close the connection cleanly:
Disconnect-ExchangeOnlinePowerShell will ask you to confirm. Type Y and press Enter. The connection closes and you can close PowerShell. If you do not disconnect and just close PowerShell, the connection will eventually time out on its own, but disconnecting properly is faster and cleaner.
If you need to connect again later, just open PowerShell and run Connect-ExchangeOnline again. You do not need to reinstall anything — the module stays on your computer.
Frequently Asked Questions
What if I get an error that says "the term Connect-ExchangeOnline is not recognized"?
The Exchange Online Management module did not install correctly. Open PowerShell and run Install-Module -Name ExchangeOnlineManagement -Repository PSGallery -Force -AllowClobber again. Make sure you wait for the installation to finish before running Connect-ExchangeOnline. If the error persists, close PowerShell completely and open it again — sometimes PowerShell needs to restart to recognize a newly installed module.
Can I use the old PowerShell 5 instead of PowerShell 7?
The Exchange Online Management module works with PowerShell 5, but Microsoft recommends PowerShell 7 because it is faster and more secure. If you are already using PowerShell 5 and it works for you, you can keep using it. Just make sure you have the latest version of the Exchange Online Management module by running Update-Module -Name ExchangeOnlineManagement.
How do I know what commands I can run?
Type Get-Command -Module ExchangeOnlineManagement to see every available command. The list will be long. To search for a specific task, type Get-Command -Module ExchangeOnlineManagement | Where-Object {$_.Name -like "*Mailbox*"} to see all commands with "Mailbox" in the name. Replace "Mailbox" with whatever you are trying to do.
What if my organization requires me to use a different account to manage Exchange?
When you run Connect-ExchangeOnline, the login window lets you enter any Microsoft 365 account. If you need to use a different account than the one you normally log in with, just enter that account's email and password in the login window. You do not need to change anything in PowerShell itself.
Can I automate tasks so I do not have to type commands every time?
Yes. You can write a PowerShell script — a text file with a list of commands — and run it all at once. Save your commands in a file with a .ps1 extension (like mailbox-report.ps1), then run it by typing .\mailbox-report.ps1 in PowerShell. Scripts are useful for tasks you do regularly, like generating reports or updating settings across many mailboxes at once.