The PowerShell Team at Microsoft have put in a lot of work to port PowerShell to other (non-Windows) systems. As part of their porting efforts, they’ve also ported OpenSSH over to Windows, but that’s not what this post is about.
I manage a number of client tenancies hosted on Microsoft Office 365. While the web based admin console is continually being improved, occasionally I come across a task that I need to perform and the only way to do it is via PowerShell.
The team writing PowerShell are not long-time Mac experts (by their own admission) and one of the decisions they made early on in the development process was to use the Homebrew package manager instead of, say, MacPorts. The PowerShell software needs to use OpenSSH libraries to communicate with remote hosts (e.g. Office 365) and there are some hardcoded library paths in the software that reference the OpenSSH libraries installed by Homebrew.
While Homebrew is very popular, I will not use it on any systems that I manage because it changes the ownership of core system folders. This, IMHO, is not The Right Way™ to do things. Further, Homebrew explicitly does not support being run as root (e.g. via sudo) so you can’t fix the permissions and have Homebrew still work.
MacPorts is more of a traditional package manager – it doesn’t change system permissions and you need to be root to use it to install software on your system.
Fortunately, you can symlink the OpenSSH library location from MacPorts to where Homebrew puts it, and then PowerShell is quite happy to use it.
sudo port install openssl sudo mkdir -p /usr/local/opt/openssl sudo ln -s /opt/local/lib /usr/local/opt/openssl/lib
Once you’ve done this, then PowerShell remote sessions should work as expected, e.g. via
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
I am trying to get this to work. I have MacPorts and have already done:
sudo port install openssh
sudo port install openssl
I tried to do your:
sudo ln -s /opt/local/lib /usr/local/opt/openssl/lib, however i get an error that path does not exist.
I have PowerShell Core 6.0.2 so I’m not sure what all I need to be able to connect to O365. The error I’m getting is:
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.
At line:1 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.NewPSSessionCommand
Here is my $PSversiontable
Name Value
—- —–
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Darwin 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RE…
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Try seeing which path doesn’t exist.
In the Terminal, type:
ls -al /opt/local/lib
and then type
ls -al /usr/local/opt/openssl/lib
See if one or both of those folders are there or not.
i’m trying to set PowerShell remoting working on Mac OS Catalina
Can you explain the logic behind the suggestion sym linking ?
–example–
sudo port install openssl
sudo mkdir -p /usr/local/opt/openssl
sudo ln -s /opt/local/lib /usr/local/opt/openssl/lib
–example–
I don’t like to use Homebrew, mainly for legacy reasons now, and instead use MacPorts. These commands are needed to symlink the OpenSSL libraries from MacPorts to where Homebrew puts them as some PowerShell modules have this path hard-coded into them.
Great instructions! I’m using Catalina and had trouble with OpenSSL version, so posting here in case it helps someone else.
Powershell error was “This parameter set requires WSMan, and no supported WSMan client library was found.”
Downgrading OpenSSL from v1.1 to v1.0 worked for me.
How did you downgrade Openssl?
I’m not sure – I’m running PowerShell via OpenSSL libraries installed in MacPorts and I’m specifically not upgrading them in case it breaks PowerShell.
Install openssl 1.0 in addition to openssl 1.1:
sudo port install openssl10
Symlink the library of openssl 1.0:
sudo mkdir -p /usr/local/opt/openssl
sudo ln -s /opt/local/lib/openssl-1.0 /usr/local/opt/openssl/lib
Got Powershell running on M1 in new MacOSX Montery with Modern Autentication against Exchange Online
without Macports or Homebrew…
PS /Users/kisu> $PSVersionTable
Name Value
—- —–
PSVersion 7.2.0-preview.10
PSEdition Core
GitCommitId 7.2.0-preview.10
OS Darwin 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS /Users/kisu> openssl
OpenSSL> version
LibreSSL 2.8.3
Nice one. I can see that it’s the arm64 version of PowerShell 7.2 working with the native arm64 OpenSSL libraries.
Is this using the latest version of jborean’s PSWSMan modules? I thought that they were all still x86_64.