Connecting to Exchange Online using MFA and ISE without EXO PowerShell Module

PowerShell

How to connect to Exchange Online using MFA without the Exchange Online PowerShell Module. If you have MFA enabled for your Exchange Online Admin accounts (which of course, you should), you will probably know that you cannot connect to Exchange Online using the normal PowerShell console, as detailed here https://cloudrun.co.uk/powershell/connecting-to-office-365-using-powershell/

The usual method of connecting with MFA is to simply download and install the Exchange Online PowerShell module from the Exchange admin center (EAC), see here: https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps, and then connect using Connect-EXOPSSession -UserPrincipalName user@domain.com. However, you may want to use the normal PowerShell console or ISE to run scripts, and often the ClickOnce package does not work due to IE security settings or other reasons so can be problematic to use. So here is how you can connect to Exchange Online using MFA.

  1. First, download and install the EXO PowerShell module from the EAC as above. We are not going to run it, but you do need to have it installed.
  2. Then simply use the following code to load the module into a normal console:
1
2
3
4
5
6
7
Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0") `
-Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName`
|?{$_ -notmatch "_none_"} | select -First 1)

$EXOSession = New-ExoPSSession

Import-PSSession $EXOSession
Posted in PowerShell

Related Posts

1 Comment

  1. Pingback:Connecting to Office 365 using PowerShell - Cloudrun

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: