Wednesday, April 24, 2024

Exchange Online Powershell failed to connect when using MFA

If you use MFA (multi factor authentication) you might very soon recognize that the normal power shell connection is not working (e.g. you might get an “access denied”) error:

The full error message is:

New-PSSession : [] Connecting to remote server failed with the following error message :
2:46:41 PM] Access Denied For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : -2144108477,PSSessionOpenFailed

To use PowerShell with MFA you need to perform the following steps:

1.) Login to the Exchange Online ECP ( and switch to the Hybrid section. There is a 2nd option, which offers “Exchange Online PowerShell Module supports multi-factor authentication” which needs to be installed

2.) Once installed you can use the following PowerShell commands to connect to Exchange Online via PowerShell using MFA:

$office365UserPrincipalName = ""
$PSExoPowershellModuleRoot = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -ErrorAction SilentlyContinue -Force | Select -Last 1).DirectoryName
$ExoPowershellModule = "Microsoft.Exchange.Management.ExoPowershellModule.dll";
$ModulePath = [System.IO.Path]::Combine($PSExoPowershellModuleRoot, $ExoPowershellModule);

Import-Module $ModulePath;

$Office365PSSession = New-ExoPSSession -UserPrincipalName $office365UserPrincipalName -ConnectionUri ""

Import-PSSession $Office365PSSession

More info´s can be found here:

– Connect to Exchange Online PowerShell using multi-factor authentication

Using PowerShell ISE to connect to Exchange Online when MFA is enabled

Related Articles


Please enter your comment!
Please enter your name here

Stay Connected

- Advertisement -

Latest Articles