Need to connect to Exchange Online to manage features or even work on a migration? This is where the Exchange Online PowerShell module can really help you. In this blog post I'll walk you through the steps needed to install the components and start to use them.
Open your PowerShell window or Windows Terminal session as Administrator. 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
Now we can 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 start to interact with Exchange Online via PowerShell.
Issue the command:
Connect-ExchangeOnline -UserPrincipalName email@example.com
Enter an email address that has permissions to interact with you Exchange setup. A pop up or sign in window will open up, you maybe required to put in your username and password and approve a sign in via your multi-factor authentication (MFA) app.
After verification has completed the PowerShell window will display a banner showing some 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 firstname.lastname@example.org -ShowBanner:$false
Disconnect Exchange Online
It's important 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 best practice.
If you issue the following command:
It will clean up session objects, local files and will also remove the access token from cache.