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 : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message :
[ClientAccessServer=VI1PR08CA0018,BackEndServer=,RequestId=1c6b263f-08cf-1234-1234-123456789091,TimeStamp=1/12/2018
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 (https://outlook.office365.com/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 = "admin@emea.contoso.com"
$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 "https://outlook.office365.com/powershell-liveid/"
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
The Admin enclave delivers the latest news, quick tips, useful tricks, and in-depth tutorials for IT pros working with IT solutions (e.g. Microsoft Sharepoint, Microsoft Exchange, Microsoft Skype for Business, Joomla, ...).
Follow Us
Recent Posts
How to connect a Osram On/Off Plug with Phoscon/deCONZ
Freitag, 20. März 2020Update TPM Firmware on Windows 10 1909
Samstag, 15. Februar 2020Switch your PC from BIOS to UEFI
Dienstag, 07. Januar 2020WLAN 6 (AX) released
Montag, 23. September 2019Use deCONZ to perform an OTA firmware update of OSRAM devices
Samstag, 23. März 2019Popular Posts
How to fix “The program can’t start because MSVCR110.dll is missing from your computer.” error on Windows
Sonntag, 07. April 2013[RESOLVED] You do not have the permission to send the message on behalf of the specified user
Mittwoch, 16. November 2016[RESOLVED] Exchange 2013/2016 hub transport Mail.que file large in size
Donnerstag, 13. Oktober 2016[RESOLVED] The Open Procedure for service XXX in DLL "C:\Windows\System32\XXX.dll" failed. Performance data for this service will not be available. The first four bytes (DWORD) of the Data section contains the error code
Mittwoch, 08. März 2017[RESOLVED] "The client and server cannot communicate, because they do not possess a common algorithm"
Mittwoch, 13. Juli 2016