Technical Guides

Connect to Exchange Online with PowerShell

Install Microsoft's module, sign in with your administrator account, and verify the Exchange Online connection.

5 min read
Illustrated command window connected to a cloud mailbox.

Before you begin

Use a patched, supported Windows 11 PC, or Windows 10 covered by an active ESU program or a still-supported LTSC release. Have your Microsoft 365 sign-in name and your organization’s tenant ID ready.

Confirm that your account can use Exchange Online PowerShell, has the Exchange permissions needed for your task, and meets your organization’s MFA and device requirements. Use the least-privileged suitable role; Global Administrator is not required just to connect.

These connection instructions cover Microsoft 365 commercial and GCC tenants. GCC High and DoD require different connection settings.

Check PowerShell version

Open Windows PowerShell or PowerShell 7 normally. Administrator elevation is not required for this current-user module installation. Run this command, then select the matching version below. If your version isn’t listed, don’t select the nearest version—check Microsoft’s compatibility guidance before continuing.

Use code with caution.

PowerShell
$PSVersionTable.PSVersion.ToString()

Only module setup differs; sign-in and verification are shared.

These steps connect Windows PowerShell 5.1 on Windows 10 or 11, subject to the Windows support requirements above, to Exchange Online using Microsoft’s current module. .NET Framework 4.7.2 or later is required.

Example version output; your build numbers may differ:

5.1.26100.1

Install Exchange module

Check whether ExchangeOnlineManagement is already available in this PowerShell application:

PowerShell
Get-Module -ListAvailable -Name ExchangeOnlineManagement | Select-Object Name, Version

Check the version shown:

  • Nothing listed: Run the installation command below.
  • Only 3.10.x listed: Already installed—skip to Sign in to M365.
  • Any other version listed: Check Microsoft’s compatibility guidance before continuing.
PowerShell
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Repository PSGallery

This installs the module from the PowerShell Gallery for your current Windows user only.

If prompted, approve the following if your organization permits them:

  • NuGet provider
  • PSGallery repository

Wait for the PowerShell prompt to return without an error.

Sign in to Microsoft 365

The connection command below loads the installed module automatically.

Replace admin@example.com below with your Microsoft 365 administrator sign-in name—not your Windows username.

PowerShell
Connect-ExchangeOnline -UserPrincipalName 'admin@example.com'

Complete Microsoft’s sign-in and MFA prompts if requested. When the command finishes, verify the connection.

Verify the account & tenant

PowerShell
Get-ConnectionInformation |    Format-List UserPrincipalName, TenantID, State, IsEopSession

Illustrative output—not a live test result:

UserPrincipalName : admin@example.com
TenantID          : 11111111-2222-4333-8444-555555555555
State             : Connected
IsEopSession      : False

Check that the account is yours, the tenant ID matches your organization’s known ID, State is Connected, and IsEopSession is False.

Find your Microsoft 365 tenant ID in the Microsoft Entra admin center under:
Entra ID (Identity) → Overview → Properties → Tenant ID.

This lookup requires at least Global Reader access. If you don’t have access, ask an authorized administrator for your tenant ID.

If details differ, no result appears, or unexpected extra connections appear, stop and resolve that before running Exchange commands.

Stay in this PowerShell window. If you close it, the module remains installed, but you’ll need to repeat Sign in to M365 in a new window—no reinstallation needed.

You can now run the Exchange Online commands within PowerShell.

Disconnect

PowerShell
Disconnect-ExchangeOnline -Confirm:$false

Disconnecting closes your Exchange connection cleanly and helps avoid reaching session limits. No confirmation prompt or output is expected.

Troubleshooting

“Running scripts is disabled”: if your organization permits it, open PowerShell as administrator and run:

PowerShell
Set-ExecutionPolicy RemoteSigned

This changes the computer-wide execution policy. Do not override a managed policy; ask IT if it remains blocked. Close that window, reopen PowerShell normally, and retry sign-in.

Sign-in fails: use a normal PowerShell window under your signed-in Windows user, not Run as different user. Your Microsoft 365 administrator account can still be different. If Microsoft rejects the device or sign-in, have your administrator review the access policy.

Connected, but a command is denied or missing: Confirm your account has the Exchange permissions required for that command.

“Could not load file or assembly”: Check that your PowerShell and Exchange module versions match the instructions above, then retry in a fresh PowerShell window before loading other modules. If the error persists, save the complete message—including the assembly name and version—for further troubleshooting.

References