For quite some time, it has not been possible to connect to Office 365 / Exchange Online with PowerShell, if your tenancy is using Modern Authentication (i.e. requiring a MFA prompt)
While there were a couple of workarounds to connect using Basic authentication, until recently there was no solution for Modern Auth. Connecting to Exchange Online with Modern Auth required a whole new PowerShell module, and that module was only available on Windows.
Fortunately, Microsoft have ported the EXO V2 module to macOS and Linux, so now it’s possible to connect to Exchange Online from non-Windows platforms and use Modern Auth.
First, you need to make sure you have an up-to-date version of PowerShell installed. Head on over to the GitHub repository and download the latest release that isn’t a Preview Release (look for the green Latest release tag)
Then, once you have downloaded and installed it, launch PowerShell as root e.g.
Then, in the PowerShell session, install the EXO V2 module by typing
Install-Module -Name ExchangeOnlineManagement
You may, if this is the first time you’ve installed any modules in PowerSHell, also need to set the Execution Policy to allow remote signed modules via
Once the EXO V2 module is installed, you can then connect to Exchange Online by simply typing
Connect-ExchangeOnline. This will launch your browser so that you can authenticate, including responding to the MFA prompt, and then once you’ve logged in you can close the browser and continue the rest of your PowerShell session in the Terminal.
If it is a clean installation of PowerShell, and you haven’t done any tweaks with OpenSSL Libraries to get WSMan working (and you’ll likely remember if you did have to go through all of this) you may also need to install a WSMan library – there’s also one on the PowerShell Gallery which you can install via
Install-Module -Name PSWSMan