Need to connect to Exchange Online to manage features or even work on a migration? This is where the Exchange Online PowerShell module can help you. In this blog post, I'll walk you through the steps needed to install and start using the components.
Open your PowerShell window or Windows Terminal session as Administrator. Now run the command:
Install-Module PowershellGet -Force
If you are asked to install the NuGet provider, press Y and then Enter.
Install Exchange Online Management Module
We can now install the Exchange Online Management module. To do this, we run the command:
Install-Module -Name ExchangeOnlineManagement
If asked, press Y and then Enter.
Connect to Exchange Online PowerShell V2
Now that everything is installed, it's time to interact with Exchange Online via PowerShell.
Issue the command:
Connect-ExchangeOnline -UserPrincipalName firstname.lastname@example.org
Enter an email address that has permissions to interact with your Exchange setup. A pop-up or sign-in window will open; you may be required to enter your username and password and approve a sign-in via your multi-factor authentication (MFA) app.
After the verification, the PowerShell window will display a banner showing new commands and any information. If you don't want to see that banner, you can use this command to connect to Exchange Online:
Connect-ExchangeOnline -UserPrincipalName email@example.com -ShowBanner:$false
Disconnect Exchange Online
It's essential to disconnect the remote PowerShell session when you’re finished. If you close the Exchange Online PowerShell Module window without disconnecting the session, you will still be seen as using a remote PowerShell session, and that's not the best practice.
If you issue the following command:
It will clean up session objects and local files and remove the access token from the cache.