Skip to main content
Five Steps for Cloud Compliance Readiness·A practical playbook for security teamsDownload
Guide · Microsoft 365

How to connect to Exchange Online PowerShell in Microsoft 365

  • Updated 25 Nov 2026

This guide shows how to install the Exchange Online PowerShell module, sign in with modern authentication and MFA, confirm the connection and sign out cleanly. It is written for Microsoft 365 administrators who need to run Exchange Online cmdlets for the first time.

Before you start

  • Role: signing in only needs an account that is allowed to use PowerShell. What you can do afterwards depends on role-based access control. Microsoft lists the Exchange Administrator role in Microsoft Entra, or the Organization Management or Recipient Management role group in Exchange Online, for checking and changing PowerShell access, and explains how to find the permissions any cmdlet needs. Microsoft recommends the role with the fewest permissions over Global Administrator.
  • Shell: Windows PowerShell 5.1 or PowerShell 7. Windows PowerShell 5.1 needs .NET Framework 4.7.2 or later (Windows 11 already has it). Recent module versions need a recent PowerShell 7, so check the supported-versions table in the Microsoft article if you use PowerShell 7.
  • Module: ExchangeOnlineManagement from the PowerShell Gallery. On Windows, REST-based connections also need the PowerShellGet and PackageManagement modules.
  • Network: your computer must reach Microsoft 365. Microsoft notes that TCP port 80 should be open too.
  • Not covered: unattended scripts, which should use app-only authentication or a managed identity instead of a person's sign-in.

Step by step

Steps 1, 3, 4 and 5 only read or end the session. Step 2 changes your own computer and is marked CHANGE (your computer). Only the last step, which is optional, changes the tenant.

  1. Check your shell and any existing module (read-only).
    $PSVersionTable.PSVersion
    Get-InstalledModule ExchangeOnlineManagement | Format-List Name,Version,InstalledLocation
    If the second command finds nothing, the module is not installed yet.
  2. CHANGE (your computer): install or update the module. On Windows PowerShell 5.1, Microsoft also lists setting the execution policy to RemoteSigned as a prerequisite:
    Set-ExecutionPolicy RemoteSigned
    Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser
    Update-Module -Name ExchangeOnlineManagement -Scope CurrentUser
    Use Install-Module the first time and Update-Module afterwards.
  3. Sign in (read-only session). Replace the example address with your own admin account:
    Import-Module ExchangeOnlineManagement
    Connect-ExchangeOnline -UserPrincipalName admin@contoso.onmicrosoft.com
    Enter your password in the sign-in window, then complete MFA when prompted. In PowerShell 7 the prompt opens in your default web browser. This uses modern authentication and works with MFA, and Basic authentication is not used.

    Variations from the Microsoft article:

    • No browser on the machine (PowerShell 7): Connect-ExchangeOnline -Device, then enter the code at the device sign-in page on another device.
    • Managing a customer tenant as a partner or guest: add -DelegatedOrganization customer.onmicrosoft.com.
    • Sovereign clouds: add -ExchangeEnvironmentName, for example O365USGovGCCHigh. Standard Microsoft 365 needs no value.
    • WAM-related errors on module 3.7.2 or later: add -DisableWAM.
  4. Confirm the session and try a read-only cmdlet.
    Get-ConnectionInformation
    Get-AcceptedDomain
  5. Disconnect when you are finished.
    Disconnect-ExchangeOnline -Confirm:$false
    Microsoft warns that closing the window without disconnecting can use up the sessions available to you until they expire.
  6. CHANGE (tenant, only if sign-in is refused): re-enable PowerShell access for one user. Every account can use Exchange Online PowerShell by default, but an admin may have turned it off. First read the status (read-only):
    Get-User -Identity "admin@contoso.onmicrosoft.com" | Format-List EXOModuleEnabled
    If it shows False and the account should have access, an administrator with the right role runs:
    Set-User -Identity admin@contoso.onmicrosoft.com -EXOModuleEnabled $true
    If you are locked out completely, Microsoft suggests creating a new admin account in the Microsoft 365 admin center and using it to restore access.

Check it worked

These commands only read.

Get-ConnectionInformation
Get-AcceptedDomain
Get-User -Identity "admin@contoso.onmicrosoft.com" | Format-List EXOModuleEnabled

If Connect-ExchangeOnline finished without errors you are connected. Get-ConnectionInformation should list one connection with State Connected, your account under UserPrincipalName and a TokenStatus of Active. Get-AcceptedDomain should list the domains of your organisation, and EXOModuleEnabled should be True for the account you use.

Common mistakes

  • Trying the old Basic authentication or OAuth-token New-PSSession methods. Microsoft lists them for history only and they are no longer supported.
  • Closing the window instead of running Disconnect-ExchangeOnline, which uses up available sessions.
  • Using an account whose profile path contains special PowerShell characters such as $. Connect and disconnect commands can fail; use another account.
  • Missing PowerShellGet or PackageManagement on Windows, which causes errors such as Update-ModuleManifest not being recognised.
  • Importing other modules first. A System.IdentityModel.Tokens.Jwt assembly error means a module conflict; connect in a new Windows PowerShell window before importing other modules.
  • Using a federated account when your identity provider is not publicly reachable. Microsoft says to use a non-federated account for that case.
  • Disabling PowerShell access for everyone in one command and including admins. Microsoft warns that a bulk Set-User -EXOModuleEnabled $false can lock out your administrators, so exclude them.
  • Running an old PowerShell 7 with a new module version. Newer module versions require newer PowerShell 7 builds.
  • Running day-to-day work under Global Administrator when a narrower role would do.

How ConfigCobra helps

ConfigCobra is read-only: it never changes your Microsoft 365 tenant. It reads the tenant with read-only Microsoft Graph permissions, with no agents and no admin password sharing, and assesses it against the CIS Microsoft 365 Foundations Benchmark v7.0.0 (160 controls, 143 of them automated). The related checks below cover Exchange Online settings you will reach through this PowerShell session.

When a control fails, ConfigCobra can give you a copy-paste remediation script (PowerShell or admin portal steps) for that finding, and remediation impact analysis shows which users, mailboxes and policies a fix would affect before you apply it. The inventory covers mailboxes and has a built-in risk view for external mail forwarding.

See where your Microsoft 365 stands

A read-only assessment against the CIS benchmarks, prioritised so you know what to fix first.

Get in touch

Let's talk.

Whether you're evaluating ConfigCobra, running an audit, or managing a client fleet — we respond within one business day.

Free trial