skip to Main Content

Connect to Exchange Online PowerShell using MFA

How to connect to Exchange Online in Office 365 with PowerShell using MFA? It’s great that the organization enabled MFA when using Office 365. It’s recommend to enable MFA because of security. Connecting to Exchange Online PowerShell with MFA is a bit different then connecting without MFA. In this article, you will learn how to connect to Office 365 with PowerShell when you have MFA enabled.

Prerequisites Exchange Online PowerShell Module

Installing the PowerShell Module is a one time process. You don’t have to download and install it on the machine every time you want to connect to Exchange Online. Install the module on the Management Server or Exchange Server.

Windows versions

Before we start installing the module, make sure that you use one of the following Windows versions:

  • Windows 10
  • Windows 8.1
  • Windows Server 2019
  • Windows Server 2016
  • Windows Server 2012 or Windows Server 2012 R2

Windows Remote Management (WinRM)

Windows Remote Management (WinRM) on the machine needs to allow Basic authentication (it’s enabled by default). Verify that Basic authentication is enabled. Run Command Prompt as administrator.

If you don’t see the value Basic = true, run the command to enable Basic authentication for WinRM.

Windows PowerShell Execution Policy

Windows PowerShell needs to be configured to run scripts, and by default, it isn’t. To require all PowerShell scripts that you download from the internet are signed by a trusted publisher. Run PowerShell as administrator.

Install Exchange Online PowerShell Module

Start Internet Explorer and log into Exchange Admin Center.

In the EAC, go to Hybrid > Setup and click the appropriate Configure button to download the Exchange Online PowerShell Module for multi-factor authentication.

If the download does not work, get it from the following direct link. Make sure that you copy and paste or click the link in Internet Explorer.

Connect to Exchange Online PowerShell using MFA download module

Click the Install button.

Connect to Exchange Online PowerShell using MFA install module

PowerShell will start after the installation finished.

You can close the PowerShell Module if you want to connect later. You can find the Microsoft Exchange Online PowerShell Module in the start menu and on the desktop.

Connect to Exchange Online PowerShell using MFA module installed start menu

In the next step, you will connect to Exchange Online.

Connect to Exchange Online PowerShell by using MFA

Start Microsoft Exchange Online PowerShell Module. Make a connection to Exchange Online in Office 365.

In the sign-in window that opens, enter your password, and then click Sign in.

Connect to Exchange Online PowerShell using MFA enter code

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 Azure Authenticator app on your mobile phone).

In the verification window that opens, enter the verification code, and then click Verify.

After the verification succeeds, you will get back to the PowerShell window.

How do you know that the connection to Exchange Online PowerShell worked?

Run the Get-Mailbox cmdlet to list the mailboxes in Exchange Online.

What if you want to use PowerShell ISE instead of the Exchange Online PowerShell Module application? Read the article: Connect to Exchange Online PowerShell with ISE using MFA.

Sign out from PowerShell Online when you are finished

Be sure to disconnect the remote PowerShell session when you’re finished. If you close the Exchange Online 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.

Conclusion

In this article, you learned how to connect to Exchange Online in Office 365 with PowerShell using MFA. Install the Exchange Online PowerShell Module. After that, connect to Exchange Online in Office 365. Did you enjoy this article? You may also like Disable NIC Power Management in Exchange best practice. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Connect with ALI TAJRAN on social media. Read more »

This Post Has 2 Comments

  1. After connecting remotely to Exchange online using MFA and run a pipeline conmand i got this error. I couldn’t find a solution for this in the net:

    Creating a new Remote PowerShell session using MFA for implicit remoting of “Get-InboxRule” command …
    Creating a new Remote PowerShell session using MFA for implicit remoting of “Remove-InboxRule” command …
    Cannot invoke the pipeline because the runspace is not in the Opened state. Current state of the runspace is ‘Closed’.
    + CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdletHelperRunspace) [], InvalidRunspaceStateException
    + FullyQualifiedErrorId : InvalidSessionState,outlook.office365.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top