Our thinking


Connect to ExchangeOnline with PowerShell from macOS

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.

https://www.powershellgallery.com/packages/ExchangeOnlineManagement/2.0.5

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)

https://github.com/PowerShell/PowerShell/releases

Then, once you have downloaded and installed it, launch PowerShell as root e.g. sudo pwsh

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 Set-ExecutionPolicy RemoteSigned

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

5 thoughts on “Connect to ExchangeOnline with PowerShell from macOS

  1. For M1 Macs

    sudo port install openssl10 +universal
    sudo mkdir -p /usr/local/opt/openssl
    sudo ln -s /opt/local/lib/openssl-1.0 /usr/local/opt/openssl/lib

    1. This code snippet installs a Universal version of OpenSSL 1.0 using Mac Ports. It then symlinks it to a location where PowerShell expects to find it having been installed by Homebrew. OpenSSL 1.0 is a hard requirement for WSman, however the built-in WSman library only works if you’re using legacy authentication.

  2. I believe the PSWSMAN module also requires you to run Install-WSMan after you installed the ps module as root. Without that it will not install the new files into place?

    1. I can’t remember having to run Install-WSMan after the Install-Module for it, but I’ll take note of what I did in more detail when I’m setting up a new M1 Mac mini next week and update this post.

Leave a Reply