macOS can't use New-PSSession to Connect to O365 from PowerShell Host - WSMAN client library not found
See original GitHub issueSteps to reproduce
Same issue as described here: https://github.com/PowerShell/PowerShell/issues/5561
except when using Microsoft.PowerShell.SDK (6.2.3) instead of PowerShell CLI
- Create a netcoreapp2.2 console application on Mac OS Mojave
- Add PackageReference to Microsoft.PowerShell.SDK (6.2.3)
- Add code to connect to O365:
var rs = RunspaceFactory.CreateRunspace();
rs.Open();
using (var ps = System.Management.Automation.PowerShell.Create())
{
ps.Runspace = rs;
var initializationScript = $@"
$ErrorActionPreference = 'Stop'
try {{ Set-ExecutionPolicy Unrestricted }} catch {{}} # not supported on non-Windows platforms
$UserCredential = New-Object System.Management.Automation.PSCredential('******', (ConvertTo-SecureString '******' -AsPlainText -Force))
$Option = New-PSSessionOption
$Option.IdleTimeout = [TimeSpan]::FromSeconds(60) # inline setting of this property via New-PSSessionOption is not supported on non-Windows platforms
$Session = New-PSSession -SessionOption $Option -ConfigurationName Microsoft.Exchange -ConnectionUri 'https://outlook.office365.com/powershell-liveid/' -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-Module (Import-PSSession $Session -DisableNameChecking) -Global
";
await ps.AddScript(initializationScript).InvokeAsync();
}
Error:
Unhandled Exception: System.AggregateException: One or more errors occurred.
(This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.) ---> System.Management.Automation.CmdletInvocationException: This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system. --->
System.Management.Automation.Remoting.PSRemotingTransportException: This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system. ---> System.DllNotFoundException: Unable to load shared library 'libpsrpclient' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibpsrpclient, 1): image not found
at System.Management.Automation.Remoting.Client.WSManNativeApi.WSManInitialize(Int32 flags, IntPtr& wsManAPIHandle)
at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.WSManAPIDataCommon..ctor()
If I set DYLD_PRINT_LIBRARIES to 1, I see the following when running from C# right before the error:
dyld: loaded: /Users/jeff/.nuget/packages/microsoft.powershell.native/6.2.0/runtimes/osx/native/libpsrpclient.dylib
dyld: unloaded: /Users/jeff/.nuget/packages/microsoft.powershell.native/6.2.0/runtimes/osx/native/libpsrpclient.dylib
Works:
- Install PowerShell CLI (6.4.0) (on the exact same machine)
- Run
sudo ln -s /opt/local/lib /usr/local/opt/openssl/lib
(this doesn’t seem to help the C# code any) - Run the exact same script
If I set DYLD_PRINT_LIBARIES to 1 for the CLI, I see the following right before the connection succeeds:
dyld: loaded: /usr/local/microsoft/powershell/6/libpsrpclient.dylib dyld: loaded: /usr/local/microsoft/powershell/6/libmi.dylib dyld: loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
so the problem is specific to the SDK…and the ln command fix doesn’t seem to work for the SDK.
Expected behavior
Doesn’t throw error
Actual behavior
Throws error
Environment data
Mac OS Mojave
Issue Analytics
- State:
- Created 4 years ago
- Comments:74 (8 by maintainers)
Top Results From Across the Web
Error "no supported WSMan client library was found." with ...
I get error from PowerShell: Enter-PSSession: This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is ...
Read more >Connect to Exchange Online PowerShell From MacOS
PS /Users/userone> $Session = New-PSSession -ConfigurationName Microsoft. ... parameter set requires WSMan, and no supported WSMan client library was found.
Read more >macOS: This parameter set requires WSMan (opennssl via ...
Running macOS Big Sur, I installed both powershell from GitHub as well ... requires WSMan, and no supported WSMan client library was found....
Read more >Powershell 7 - WSMAN issue - Tech Support - MPU Talk
I trying PowerShell 7 on MacOS and I have installed SharePoint Online Management Shell but the "Connect-SPOService" command is not found. Get- ...
Read more >Get PowerShell remoting working on macOS without installing ...
The error I'm getting is: New-PSSession : This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Why the &$@! Would you close this issue??
I had the same issue, managed to solve it by linking an older openssl version from brew with
brew switch openssl 1.0.2s