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

The customer here wished to be able to use the PowerShell ISE and still be able to connect with MFA (Multi-Factor Authentication) enabled for their account.

We already have a PowerShell module designed to allow connection with MFA enabled, but there is no direct integration of it with the PowerShell ISE.

When the Microsoft Exchange PowerShell app ( is installed and executed, it launches a PowerShell session and runs a script to load the necessary modules and functions into the current PowerShell execution to provide the cmdlet.

The files related to the app are all loaded into a folder with a path similar to (as this is a Click To Run app):

To find the folder with the files in it, I first went to my Start Menu\Programs folder to find the shortcut for it:
C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Microsoft Corporation


When I get the properties of that item, I see:


Looking at the Folder path value, I now know the name of the folder the module points to, I can go to the C:\Users\<username>\AppData\Local\Apps\2.0  folder and find the appropriate folder.

To successfully use the Connect-EXOPSSession cmdlet in the ISE, I need to "dot load" the CreateExoPSSession.ps1 script found in the above folder into my ISE execution. When it runs, it loads the necessary modules and functions into the session so that the Connect-EXOPSSession cmdlet is available and works to connect to Exchange Online with MFA enabled. This is done with the following syntax after changing to the location of the module:
. .\CreateExoPSSession.ps1

Update 4/5/18 - One of my coworkers brought me these 2 lines that we can run, which will find the module for us and load it up in our ISE session, without having to go out and search for it ourselves:

$CreateEXOPSSession = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -ErrorAction SilentlyContinue -Force | Select -Last 1).DirectoryName
. "$CreateEXOPSSession\CreateExoPSSession.ps1"

Comments (0)

Skip to main content