Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS can't use New-PSSession to Connect to O365 from PowerShell Host - WSMAN client library not found #10600

Closed
jnevins-gcm opened this issue Sep 23, 2019 · 74 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered. Resolution-External The issue is caused by external component(s). WG-DevEx-SDK hosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules
Milestone

Comments

@jnevins-gcm
Copy link

jnevins-gcm commented Sep 23, 2019

Steps to reproduce

Same issue as described here:
#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

@jnevins-gcm jnevins-gcm added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Sep 23, 2019
@iSazonov iSazonov added the WG-DevEx-SDK hosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules label Sep 24, 2019
@iSazonov
Copy link
Collaborator

@adityapatwardhan Could you please comment the SDK issue?

@jnevins-gcm
Copy link
Author

Anyone?

@iSazonov
Copy link
Collaborator

@jnevins-gcm MSFT team is busy in the days so waiting...

@jnevins-gcm
Copy link
Author

It's been 15 days... @iSazonov @adityapatwardhan

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 11, 2019

@jnevins-gcm From previous discussions I can only say please check that libpsrpclient is installed and loaded. The same for OpenSSL.

/cc @SteveL-MSFT

@jnevins-gcm
Copy link
Author

@iSazonov - that isn’t a meaningful reply. It doesn’t seem like you’ve even read the issue

@iSazonov
Copy link
Collaborator

@jnevins-gcm Sorry for short answer.

and the ln command fix doesn't seem to work for the SDK.

libpsrpclient does not have a help logging so it would be great if you used diagnostic tools to identify broken dependencies (to ssl I guess).
And do you want to get a workaround or fix?

@jnevins-gcm
Copy link
Author

jnevins-gcm commented Oct 12, 2019

I’d be totally happy with a workaround.

I’m not super familiar with dependency analysis tools on OS X but I’m happy to try to gather some information if you could provide some guidance on what tools to use.

Thanks!

@jnevins-gcm
Copy link
Author

any update...? been about a month

@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Oct 21, 2019

I believe you need to include https://www.nuget.org/packages/Microsoft.PowerShell.Native

Native binaries for PowerShell Core

@jnevins-gcm
Copy link
Author

@SteveL-MSFT already tried this

....did you try it?

@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Oct 21, 2019

@jnevins-gcm sorry, didn't see all the details of your report. I did try this and noticed that dotnet run fails, but if I explicitly run the built exe it works (in the sense it tired to connect)

Unhandled exception. System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : Client did not get proper response from server. For more information, see the about_Remote_Troubleshooting Help topic.
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.Runspaces.Pipeline.Invoke()
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke()
   at wsman.Program.Main(String[] args) in /Users/steve/test/wsman/Program.cs:line 25

@jnevins-gcm
Copy link
Author

thanks @SteveL-MSFT - what is the difference? how can I make a debugging experience function?

@SteveL-MSFT
Copy link
Member

I don't know why dotnet run fails. You may have to bring that up in the dotnet CLI repo. Based on the traces it loads the necessary library, but unloads it for some reason. Running the exe directly doesn't unload that library.

@jnevins-gcm
Copy link
Author

Got to trying this. Same error when calling "dotnet mydll"

You sure you actually got this to work via the command line?

@jnevins-gcm
Copy link
Author

@SteveL-MSFT any updates? seems like a bug in PowerShell Core....

@jnevins-gcm
Copy link
Author

jnevins-gcm commented Nov 19, 2019

@SteveL-MSFT @iSazonov

looking to get some/any support here please. PowerShell is supposedly actively supported by Microsoft and this is clearly a bug.

@iSazonov
Copy link
Collaborator

@jnevins-gcm Sorry, I haven't Mac to investigate.
If you shared your project or sample project it would help MSFT experts.

@jnevins-gcm
Copy link
Author

The sample code I posted, exactly as is, in an out of box csproj console app will reproduce the problem.

@iSazonov
Copy link
Collaborator

Having GitHub ready-to-run project would save reviewer's time.

@jnevins-gcm
Copy link
Author

jnevins-gcm commented Nov 23, 2019

@iSazonov @SteveL-MSFT

ok....

https://github.com/JeffN825/PowerShellWSManBug

It's a simple csproj and Program.cs copied straight from my original post.

dotnet build
cd bin/Debug/netcoreapp2.2/
dotnet PowerShellWSManBug.dll 

would be great to get a resolution

GitHub
Contribute to JeffN825/PowerShellWSManBug development by creating an account on GitHub.

@iSazonov
Copy link
Collaborator

netcoreapp2.2

We never targeted 2.2. Can you try 2.1?

@jnevins-gcm
Copy link
Author

doesn't work

@jnevins-gcm
Copy link
Author

@iSazonov @SteveL-MSFT

bump...any fix for this bug? I spent the time putting together that sample...would be great if you could reciprocate.

@iSazonov
Copy link
Collaborator

@jnevins-gcm I haven't MacOs to investigate the issue, sorry. Since you are using SDK I guess you can use debugger and I suggest to use a native dll handler (see #11032) and catch a path to openssl.dylib. This can help to get understanding where is a problem or even to fix it in OS or in your code.

@jnevins-gcm
Copy link
Author

jnevins-gcm commented Nov 30, 2019

Very frustrating that there is one single person who supports/replies to bugs in PowerShell and they have no access to platforms that PowerShell claims to support.

@iSazonov how do I leverage what’s in the PR you linked to? Some basic direction would be helpful.

@vexx32
Copy link
Collaborator

vexx32 commented Nov 30, 2019

@jnevins-gcm keep in mind this is Thanksgiving weekend in the US, where the entire PS team is based. I'm sure they're all spending time with their families. 🙂

@jnevins-gcm
Copy link
Author

@pyrohaz4good this issue is regarding the SDK. Even when it works with the CLI, It doesn’t work with the SDK

@jshum
Copy link

jshum commented Feb 22, 2020

I had the same issue, managed to solve it by linking an older openssl version from brew with brew switch openssl 1.0.2s

For me 1.0.2r worked as well. I had the openssl 1.1 installed through brew but they did not work

@jnevins-gcm
Copy link
Author

@jshum CLI or SDK? This issue relates to the SDK

@jshum
Copy link

jshum commented Feb 23, 2020

Right, my comment was for CLI, but I'm guessing it may be the same underlying problem relating to the SSL library being found in the environment/path on OS X

@TravisEz13
Copy link
Member

I suspect macports would still work. The instructions are here:
#5634 (comment)

@JeffN825
Copy link

@TravisEz13 You could just try it or read the entirety of the question and you'd know it doesn't work... truly unbelievable

@JeffN825
Copy link

@TravisEz13 - it doesn’t work

@SteveL-MSFT
Copy link
Member

I understand that some folks are frustrated here, but please keep in mind we are not a huge team and we have to prioritize issues we believe have the most impact. In this specific case, we've been having discussions with EXO team to move off WSMan based remoting. The library that we were using for WSMan remoting on non-Windows has been deprecated and no longer supported by a team. New EXO cmdlets are coming with expectation that they are cross platform compatible. Sorry no timeline to announce as it's not my project.

@luckman212
Copy link

Good luck on this! Hope the new cmdlets support MFA login on macOS, similar to Connect-AzAccount from the new Az module... 🚀

@TravisEz13 TravisEz13 changed the title Mac can't use New-PSSession to Connect to O365 from PowerShell Host - WSMAN client library not found macOS can't use New-PSSession to Connect to O365 from PowerShell Host - WSMAN client library not found Apr 7, 2020
@TravisEz13
Copy link
Member

TravisEz13 commented Apr 7, 2020

Updated docs for getting libmi to work using MacPorts MicrosoftDocs/PowerShell-Docs#5726

Please note that this is a temporary solution as @SteveL-MSFT said:

we've been having discussions with EXO team to move off WSMan based remoting. The library that we were using for WSMan remoting on non-Windows has been deprecated and no longer supported by a team. New EXO cmdlets are coming with expectation that they are cross platform compatible. Sorry no timeline to announce as it's not my project.

CC @mgreenegit

@luckman212
Copy link

For now, this hack works...

brew install https://github.com/luckman212/openssl10/releases/download/1.0.2u/openssl@1.0.rb
rm /usr/local/opt/openssl
ln -s /usr/local/Cellar/openssl@1.0/1.0.2u /usr/local/opt/openssl

@JeffN825
Copy link

JeffN825 commented Apr 7, 2020 via email

@luckman212
Copy link

@JeffN825 I can't say for sure, but this symlinks into the global /usr/local/opt dir so I would expect it to work for both. Please try if you can & report back.

@jnevins-gcm
Copy link
Author

jnevins-gcm commented Apr 8, 2020 via email

@iSazonov

This comment has been minimized.

@TravisEz13
Copy link
Member

@iSazonov I hid your topic as this has NOTHING to do with the CLR. This is libmi which is hardcoded to load from this path and is deprecated.

@TravisEz13 TravisEz13 added the Resolution-External The issue is caused by external component(s). label Apr 8, 2020
@ghost
Copy link

ghost commented Apr 9, 2020

This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.

@ghost ghost closed this as completed Apr 9, 2020
@jnevins-gcm
Copy link
Author

jnevins-gcm commented Apr 9, 2020

Why the &$@! Would you close this issue??

@iSazonov
Copy link
Collaborator

@jnevins-gcm There is a long path to deprecated dependencies. It is so over last 2 years. Recommendation for remoting on MacOs is to use SSH. For O365 services, Azure modules we can only wait when they are updated.

@TravisEz13
Copy link
Member

@jnevins-gcm Here is the external issue. microsoft/omi#596 It was closed because OMI is deprecated and will not fix these issues.
This was summarized here: #10600 (comment)

@TravisEz13 TravisEz13 added the Resolution-Answered The question is answered. label Apr 11, 2020
@adin3d
Copy link

adin3d commented Oct 13, 2020

ok, so it was moved to a project were was declared "out of scope"

I think there are around two years since we wait for this, any chance for this to have a proper follow-up and timeline?

Thank you

@iSazonov
Copy link
Collaborator

@adin3d Please look last comments in #5561

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered. Resolution-External The issue is caused by external component(s). WG-DevEx-SDK hosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules
Projects
None yet
Development

No branches or pull requests