Install Exchange Online PowerShell modules

Do you 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. This blog post will guide you through the installation process and provide a step-by-step overview of utilizing its components for seamless integration and efficient operations.

Install PowerShellGetModule

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.

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