Our thinking

PowerShell and remote sessions to Office 365 / Microsoft 365 on Apple Silicon

I’ve recently switched over to an Apple Silicon MacBook Pro and overall it’s a really good machine. I do miss not having Thunderbolt ports on both sides of the laptop, mainly because whenever I want to charge it, the power outlet always seems to be on the right-hand side. But I digress…

I use PowerShell a fair bit to tweak things on Office 365 (now Microsoft 365) that you can’t get to through the web interface.

It looks like it will be a long time before Microsoft have got everything sorted out so that PowerShell can run natively on Apple Silicon, and successfully establish remote sessions.

While you can likely get the source code from GitHub to compile on an M1 (I haven’t tried this) the big hold-up will be all of the other libraries that PowerShell uses. One of the libraries used, libmi, is developed by another team within Microsoft who dropped support for macOS back in 2018.

Thankfully, due to the magic of Rosetta 2, we can still use the Intel x86_64 version, but the catch is that the entire stack needs to be x86_64.

The Terminal.app, even when running as a native arm64 app, is capable of launching x86_64 binaries, like pwsh. Due to the way that Rosetta 2 works, however, every library that PowerShell uses must also be x86_64. You can’t have an x86_64 binary load arm64 shared libraries, or vice-versa.

So, what you need to do is make sure that all of the relevant shared libraries are using the correct CPU architecture.

The steps to get this working are:

Install MacPorts

After MacPorts has installed successfully, install the OpenSSL 1.0 libraries that it needs (the libraries it uses for remote sessions will not work with newer versions). The key to this step is to make sure you install the Universal version.

sudo port install openssl10 +universal

This will install OpenSSL 1.0, along with its dependencies as universal binaries, with arm64 and x86_64 support.

Finally, because some of the libraries that PowerShell uses are brain-dead and have hard-coded library paths, make a symlink to the location where PowerShell expects to find them:

sudo mkdir -p /usr/local/opt/openssl
sudo ln -s /opt/local/lib/openssl-1.0 /usr/local/opt/openssl/lib

After you’ve done all of this, you should be able to launch Terminal normally (you don’t need to open it using Rosetta) and then launch pwsh.

Connect to Office 365 with the following snippet

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

At this stage, there is no workaround that I know of to connect to Office 365 using modern authentication (e.g. if you have multi-factor authentication enabled). This will only work from Windows. If you know how to get it working from any other platform, please let me know!

Leave a Reply