December 19, 2019

Run powershell on macOS

Powershell on Mac Keyboard

Note: This article seems to be quite popular. It was written in December 2019 but the Powershell Binaries may have been improved in the meantime. I have updated Powershell on Mac since then without issue and haven’t checked if the location of the libraries are still hard coded or if an older version of SSL is till required.

I often need to run a remote session in powershell e.g. managing online exchange.

This may sound crazy but you can run powershell on a Mac. Before I discovered this I always had to first remote desktop in to a Windows Machine or fire up a VM to be able to start the remote session.

If you google a bit you will find lots of instructions to install powershell on Mac. Most of them are outdated and some are plain wrong.

You can download the latest version of powershell for Mac (or Linux) at https://github.com/PowerShell/PowerShell. Just install the downloaded .pkg

The first thing you will notice is that starting a remote session does not work and you get a nasty error. Something like: New-PSSession : This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.

In typical fashion this error message does not really tell you what is wrong and back you go to your favourite search engine.

You will find out that the powershell application has the openssl libraries hard coded in the program. (yes, they should know better)

Apparently the location that is hard coded into powershell is the homebrew location of the openssl libraries. If you use macports, as you should, you will be provided with a workaround to create a symbolic link to the macports libraries.

There is a catch though. If your macports are up to date your macports libraries are a newer version of openssl than what powershell requires.

To list the hardcoded libraries for powershell execute the following code:

otool -L /usr/local/microsoft/powershell/6/libmi.dylib

The output will be something like:

/usr/local/microsoft/powershell/6/libmi.dylib:@rpath/libmi.dylib (compatibility version 0.0.0, current version 0.0.0)/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)/usr/lib/libpam.2.dylib (compatibility version 3.0.0, current version 3.0.0)/usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)

As you see it requires openssl 1.0.0 libraries but macports is already on openssl 1.1.1. To work arround this do the following:

port install openssl10

This will install the openssl 1.0.0 libraries in /opt/local/lib/openssl-1.0/

Now execute :

ln -s /opt/local/lib/openssl-1.0/ /usr/local/opt/openssl/lib

And low and behold remote sessions now work in powershell on the Mac.

NB. This works for macports, I have no idea if it will work for Homebrew. This was written on 19 December 2019, things can change for better or worse. You need xcode, xcode tools and macports installed.

© Arnold Greyling 2023