365 UC
Published in

365 UC

Exchange Online & Microsoft Teams PowerShell on Mac

I gave this a go back in 2016 when Microsoft announced PowerShell was available for Linux and Mac, but it was just a bit of a ballache so I kind of gave up. Then in 2018 I wrote the original version of this blog post which included how to connect to Exchange Online PowerShell but had the big caveat that you had to use basic authentication, which meant if your organisation didn’t allow legacy authentication methods or enforced MFA, it was no good to you.

Anyway, things seem to have improved greatly now, so it’s time for an update to this post.

All of this has been done on my aging MacBook with macOS Big Sur Version 11.1. As of writing the latest version of PowerShell is 7.1.1.

I have done a short version and a long version. The long version will have a lot of screenshots and a few workarounds for the various issues I saw along the way…

Short Version

Long Version

Microsoft have published some pretty good instructions here with various options for installing PowerShell. I went with the recommended process of using Homebrew rather than direct download or using binary archives.

This is pretty easy and instructions can be found here. It’s effectively just one command. Paste this into Terminal and hit Enter:

It will tell you what it’s gonna do and ask you to hit Enter to continue. Once you’ve done that you’ll need to enter your macOS administrator password to continue with the install.

After this it will go away and install Xcode (if required) and then proceed to install Homebrew. This took about 5 minutes on my machine.

You’ll know it’s finished when you see a screen similar to this:

This part is also very simple. Install PowerShell by pasting in the following command to your Terminal session and hitting Enter:

Okay, some good progress here. It would appear you can now install the ExchangeOnlineManagement module from the PSGallery using PowerShellGet and then connect to Exchange Online using modern authentication (with MFA). If for some reason your company still allow basic authentication you can us the process lower down the page. You probably shouldn’t be doing this in 2021 though and Microsoft will be stopping this soon anyway.

Install the Exchange Online Management module by running the following command:

Once this is done you can connect to Exchange Online using the following command:

A browser will open and you will go through the regular Office 365 login process. Once done, you will be told you can close the browser window.

All done.

Now, depending on your Homebrew version and depending on when you installed this you might run into an issue with a newer OpenSSL version which causes a WSMan error like below:

This parameter set reqauires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.

If you do get this you need to force Homebrew to use an earlier OpenSSL version. I used these instructions to fix this: https://medium.com/@smithua/install-openssl-1-0-2t-version-on-macos-7084ac52fa8b

Let’s hope Microsoft fix this at some point.

Again, for this you can install the MicrosoftTeams module from PSGallery using PowerShellGet.

Once this is done you can connect to Microsoft Teams using the following command:

You will be given a code to take to https://microsoft.com/devicelogin to continue your authentication. Once that is done, go back to the Terminal window and you will be authenticated.

Go to microsoft.com/devicelogin with the code
Enter the code and go through the regular O365 login process

For this, you need to follow the instructions above to install the MicrosoftTeams module from PSGallery. Microsoft recently rolled in the SFBO tools to the MicrosoftTeams module, so this is now quite an easy task.

Once done, run the following commands:

This will trigger the same https://microsoft.com/devicelogin process we saw above. Once you’ve completed the authentication process, go back to the Terminal window and run this command to import the session:

I have left this in from the previous version of the blog, but you really shouldn’t use this anymore. Microsoft will soon remove basic authentication from Exchange Online in 2021 anyway.

You can use the instructions you’d use in Windows for this but essentially you need enter your credentials and establish a session.

Huge caveat here. You need to use an account that can use basic authentication. If your account requires MFA or your organisation has disabled legacy authentication methods you will see an error similar to below.

If you have used an account where basic authentication is enabled you will be able to establish the session and run cmdlets as normal. Voila!

Remember to disconnect your PowerShell session once you’re done by running Remove-PSSession $Session



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matt Ellis

Unified Communications guy, Pompey fan, burger eater, coffee drinker...