Install Exchange Online PowerShell modules

Exchange Online Jul 19, 2022

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.

Install PowerShellGetModule

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.

Windows Terminal with PowerShell command history
Windows Terminal with PowerShell command history

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 admin@domain.com

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 admin@domain.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:

Disconnect-ExchangeOnline

It will clean up session objects and local files and remove the access token from the cache.

Windows Terminal with PowerShell command history
Windows Terminal with PowerShell command history

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.