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.
The other day I thought I’d try this again and I had some success on my Mac running the latest Mojave 10.14 macOS.
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:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
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:
brew cask install powershell
Connect to Exchange Online
Now you need to connect to Exchange Online. 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. As soon as it’s possible to use modern authentication on the Mac I will update this post.
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