Connect to Exchange Online PowerShell using multi-factor authentication


If you want to use multi-factor authentication (MFA) to connect to Exchange Online PowerShell, you can’t use the instructions at Connect to Exchange Online Using Remote PowerShell to use remote PowerShell to connect to Exchange Online. MFA requires you to install the Exchange Online Remote PowerShell Module, and use the Connect-EXOPSSession cmdlet to connect.

What do you need to know before you begin?

  • Estimated time to complete: 5 minutes

  • You can use the following versions of Windows:

    • Windows 10

    • Windows 8.1

    • Windows Server 2019

    • Windows Server 2016

    • Windows Server 2012 or Windows Server 2012 R2

    • Windows 7 Service Pack 1 (SP1)*

    • Windows Server 2008 R2 SP1*

      * For older versions of Windows, you need to install the Microsoft.NET Framework 4.5 or later and then an updated version of the Windows Management Framework: 3.0, 4.0, or 5.1 (only one). 

  • The Exchange Online Remote PowerShell Module needs to be installed on your computer. You need to do the following steps in a browser that supports ClickOnce (for example, Internet Explorer or Edge):

    Note: ClickOnce support is available in the Chromium-based version of Edge at edge://flags/#edge-click-once.

    1. Open the Exchange admin center (EAC) for your Exchange Online organization. For instructions, see Exchange admin center in Exchange Online.

    2. In the EAC, go to Hybrid > Setup and click the appropriate Configure button to download the Exchange Online Remote PowerShell Module for multi-factor authentication.In the Application Install window that opens, click Install

    3. In the Application Install window that opens, click Install
  • Windows Remote Management (WinRM) on your computer needs to allow Basic authentication (it’s enabled by default). To verify that Basic authentication is enabled, run this command in a Command Prompt:

Connect to Exchange Online PowerShell by using MFA

  1. On your local computer, open the Exchange Online Remote PowerShell Module ( Microsoft Corporation > Microsoft Exchange Online Remote PowerShell Module).
  2. Using the below example we will to connect to Exchnage Online PowerShell as the user chris@contoso.com
Connect-EXOPSSession -UserPrincipalName chris@contoso.com
  1. In the sign-in window that opens, enter your password, and then click Sign in.

    A verification code is generated and delivered based on the verification response option that’s configured for your account (for example, a text message or the Microsoft Authenticator app on your mobile phone).
  2. In the verification window that opens, enter the verification code, and then click Sign in.

Be sure to disconnect the remote PowerShell session when you’re finished. If you close the Exchange Online Remote PowerShell Module window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you’ll need to wait for the sessions to expire. To disconnect all currently open PowerShell sessions in the current window, run the following command:

Get-PSSession | Remove-PSSession

How do you know if this worked?

After Step 4, the Exchange Online cmdlets are imported into your Exchange Online Remote PowerShell Module session and tracked by a progress bar. If you don’t receive any errors, you connected successfully. A quick test is to run an Exchange Online cmdlet, for example, Get-Mailbox, and see the results.