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

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install PowerShell

brew install --cask powershell

Run PowerShell

pwsh

Install Exchange Online Management Module

Install-Module ExchangeOnlineManagement

Connect to Exchange Online

Connect-ExchangeOnline -UserPrincipalName whatever@domain.com

Install Microsoft Teams Module

Install-Module MicrosoftTeams

Connect to Microsoft Teams

Connect-MicrosoftTeams -AccountId whatever@domain.com

Connect to Skype for Business Online

$SFBOSession = New-CsOnlineSession -OverrideAdminDomain whatever.onmicrosoft.comImport-PSSession $SFBOSession -AllowClobber

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.

Installing Homebrew

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

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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:

Install PowerShell

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

brew install --cask powershell

Exchange Online

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:

Install-Module ExchangeOnlineManagement

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

Connect-ExchangeOnline -UserPrincipalName whatever@domain.com

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.

Microsoft Teams

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

Install-Module MicrosoftTeams

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

Connect-MicrosoftTeams -AccountId whatever@domain.com

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

Skype for Business Online

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:

$SFBOSession = New-CsOnlineSession -OverrideAdminDomain whatever.onmicrosoft.com

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:

Import-PSSession $SFBOSession -AllowClobber

Exchange Online using Basic Authentication

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.

$Creds = Get-Credential$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirectionImport-PSSession $Session -DisableNameChecking

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

--

--

--

Stories from the world of UC by a bunch of UC professionals…

Recommended from Medium

CQRS pattern with c# and MediatR (Part 2)

Implementing CQRS pattern with MediatR library

Flutter vs Xamarin Cross-Platform Mobile Development Compared

How to Send APK File Automatically with Fire Base App Distribution

Maven generated sources in Intellij Idea

Create Amazing Reports in OutSystems — Part I Html2Pdf

Text Generation API

Cluster Management using Apache Mesos, Marathon

How we manage clients & their expectations

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

Matt Ellis

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

More from Medium

Old Macbook pro back to 2022! ssd replacement and fan cleaning record

100 Releases of Dendron (open source note taking for devs)

The Apple Home Theater

Apple is notorious for this! Why do Apple products only last a few years? By Dennis Schleicher