PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
43.66k stars 7.08k forks source link

Can not connect to Office 365 / Exchange Online with PowerShell #5561

Closed kai-h closed 5 years ago

kai-h commented 6 years ago

I can not connect to Office 365 / Exchange Online with PowerShell. Apparently others can with the latest version of push, but it is not working for me on either macOS 10.12 or 10.13 with pwsh 6.0.0-rc

I get an error creating the New-PSSession. Depending on the exact syntax of the command I'm using, it either says New-PSSession : This parameter set requires WSMan, and no support WSMan client library was found, or PowerShell quits with an unhandled exception and abort trap 6.

Steps to reproduce

Install PowerShell 6.0.0-rc on macOS 10.12 or 10.13. Use Get-Credential to get an Office 365 administrator credential and then use New-PSSession to create a new session.

[kai@blackmac ~]$ pwsh
PowerShell v6.0.0-rc
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/kai> $PSVersionTable                                        

Name                           Value                                           
----                           -----                                           
PSVersion                      6.0.0-rc                                        
PSEdition                      Core                                            
GitCommitId                    v6.0.0-rc                                       
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: T...
Platform                       Unix                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1                                         
WSManStackVersion              3.0                                             

PS /Users/kai> $UserCredential = Get-Credential                       

PowerShell credential request
Enter your credentials.
User: admin@example.com
Password for user admin@example.com: ***********

PS /usr/local/microsoft> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection                     
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

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

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Management.Automation.Remoting.PrioritySendDataCollection.Clear()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.Finalize()
Abort trap: 6
[kai@blackmac ~]$ 

You will note from the prompt in the last line above that it's dropped me back into the bash shell.

Expected behavior

It is expected that New-PSSession will work on macOS

Actual behavior

Depending on the precise syntax of the command, New-PSSession either returns an error message: New-PSSession : This parameter set requires WSMan, and no supported WSMan client library was found Or, New-PSSession has an unhandled exception and PowerShell quits with abort trap 6.

The differences in the syntax are with the ConnectionUri - whether or not there is a trailing slash on the uri seems to make the difference. With a trailing slash, I get the error about WSMan missing. Without the trailing slash, the PowerShell session aborts.

With trailing slash:

PS /Users/kai> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection                     
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

Without trailing slash:

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

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Management.Automation.Remoting.PrioritySendDataCollection.Clear()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.Finalize()
Abort trap: 6

Environment data

PS /Users/kai> $PSVersionTable                                                                                                                                                                                Name                           Value                                                                   
----                           -----                                                                  
PSVersion                      6.0.0-rc                                                               
PSEdition                      Core                                                                   
GitCommitId                    v6.0.0-rc                                                              
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT ...
Platform                       Unix                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                
PSRemotingProtocolVersion      2.3                                                                    
SerializationVersion           1.1.0.1                                                                
WSManStackVersion              3.0                                                                    
SteveL-MSFT commented 6 years ago

This is working for me on 10.13.1. Can you confirm that in $PSHome you have libpsrpclient.dylib?

kai-h commented 6 years ago
PowerShell v6.0.0-rc
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/kai> cd $PSHome                                                       
PS /usr/local/microsoft/powershell/6.0.0-rc> ls -al *.dylib                     
-rw-r--r--  1 root  wheel    70224 31 Oct 17:27 System.Globalization.Native.dylib
-rw-r--r--  1 root  wheel    13484 31 Oct 17:27 System.IO.Compression.Native.dylib
-rw-r--r--  1 root  wheel    61460 31 Oct 17:27 System.Native.dylib
-rw-r--r--  1 root  wheel    16932 31 Oct 17:27 System.Net.Http.Native.dylib
-rw-r--r--  1 root  wheel    15132 31 Oct 17:27 System.Net.Security.Native.dylib
-rw-r--r--  1 root  wheel    46016 31 Oct 17:27 System.Security.Cryptography.Native.Apple.dylib
-rw-r--r--  1 root  wheel    75708 31 Oct 17:27 System.Security.Cryptography.Native.OpenSsl.dylib
-rw-r--r--  1 root  wheel  2571480 31 Oct 17:27 libclrjit.dylib
-rw-r--r--  1 root  wheel  6894904 31 Oct 17:27 libcoreclr.dylib
-rw-r--r--  1 root  wheel   883740 31 Oct 17:27 libdbgshim.dylib
-rw-r--r--  1 root  wheel   869664 31 Oct 17:27 libhostfxr.dylib
-rw-r--r--  1 root  wheel  1006336 31 Oct 17:27 libhostpolicy.dylib
-rw-r--r--  1 root  wheel   843792 14 Nov 11:37 libmi.dylib
-rw-r--r--  1 root  wheel  3081760 31 Oct 17:27 libmscordaccore.dylib
-rw-r--r--  1 root  wheel  2021168 31 Oct 17:27 libmscordbi.dylib
-rw-r--r--  1 root  wheel    20568  4 Nov 09:08 libpsl-native.dylib
-rw-r--r--  1 root  wheel   224784 15 Nov 07:39 libpsrpclient.dylib
-rw-r--r--  1 root  wheel   553360 31 Oct 17:27 libsos.dylib
PS /usr/local/microsoft/powershell/6.0.0-rc> 
SteveL-MSFT commented 6 years ago

@kai-h you have the right library with the right file size and permissions. Is DYLD_LIBRARY_PATH defined? What is the output of $env:DYLD_LIBRARY_PATH?

kai-h commented 6 years ago

It's undefined.

PowerShell v6.0.0-rc
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/kai> $env:DYLD_LIBRARY_PATH                                           
PS /Users/kai> 
SteveL-MSFT commented 6 years ago

What does [System.Environment]::Is64BitProcess return?

kai-h commented 6 years ago
PS /Users/kai> [System.Environment]::Is64BitProcess                             
True
SteveL-MSFT commented 6 years ago

@kai-h try (in the terminal before starting pwsh):

export DYLD_LIBRARY_PATH=/usr/local/microsoft/powershell/6.0.0-rc:${DYLD_LIBRARY_PATH}
pwsh
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
kai-h commented 6 years ago

Thank you for your persistence with this. I'm still getting the same error though.

[kai@hobbes ~]$ export DYLD_LIBRARY_PATH=/usr/local/microsoft/powershell/6.0.0-rc:${DYLD_LIBRARY_PATH}
[kai@hobbes ~]$ pwsh
PowerShell v6.0.0-rc
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

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

PowerShell credential request
Enter your credentials.
User: admin@example.onmicrosoft.com
Password for user admin@example.onmicrosoft.com: ********

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Management.Automation.Remoting.PrioritySendDataCollection.Clear()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.Finalize()
Abort trap: 6
[kai@hobbes ~]$ 
kai-h commented 6 years ago

I'd like to confirm that I can successfully connect to Office 365 from PowerShell hosted on an Azure Ubuntu virtual machine, using the exact same details as I'm trying on the Mac.

PowerShell v6.0.0-rc
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/kai>  $PSVersionTable                                                                                                                               

Name                           Value                                                                                                                        
----                           -----                                                                                                                        
PSVersion                      6.0.0-rc                                                                                                                     
PSEdition                      Core                                                                                                                         
GitCommitId                    v6.0.0-rc                                                                                                                    
OS                             Linux 4.4.0-22-generic #40-Ubuntu SMP Thu May 12 22:03:46 UTC 2016                                                           
Platform                       Unix                                                                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                      
PSRemotingProtocolVersion      2.3                                                                                                                          
SerializationVersion           1.1.0.1                                                                                                                      
WSManStackVersion              3.0                                                                                                                          

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

PowerShell credential request
Enter your credentials.
User: user@example.onmicrosoft.com
Password for user user@example.onmicrosoft.com: ********

PS /home/kai> Import-PSSession $Session
(at this point PowerShell starts loading remote modules etc and preparing the session)
kai-h commented 6 years ago

What I'm going to do in order to remove any possible issues with me having tweaked something on my Mac that is conflicting with this is set up a clean install of macOS 10.12 and then a fresh install of PowerShell 6.0.0-rc and test if it works tonight.

iSazonov commented 6 years ago

It is dup #3606

kai-h commented 6 years ago

Issue #3606 is kind-of a dup, but they also saw the error which I haven't seen occur in my testing.

New-PSSession : Unable to load DLL 'libpsrpclient':...
kai-h commented 6 years ago

I have been able to reproduce this on a clean install of macOS 10.12.6 and a clean install of PowerShell 6.0.0-rc. Everything is with default settings, new admin account created on first boot and no settings changed for the Terminal app.

Last login: Thu Nov 30 08:11:57 on ttys000
Administrators-Mac-mini:~ admin$ pwsh
PowerShell v6.0.0-rc
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/admin> $PSVersionTable                                                

Name                           Value                                           
----                           -----                                           
PSVersion                      6.0.0-rc                                        
PSEdition                      Core                                            
GitCommitId                    v6.0.0-rc                                       
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: T...
Platform                       Unix                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1                                         
WSManStackVersion              3.0                                             

PS /Users/admin> $env:DYLD_LIBRARY_PATH                                         
PS /Users/admin> [System.Environment]::Is64BitProcess                           
True
PS /Users/admin> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection                             

PowerShell credential request
Enter your credentials.
User: admin@example.onmicrosoft.com
Password for user admin@example.onmicrosoft.com: *********

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Management.Automation.Remoting.PrioritySendDataCollection.Clear()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.CloseAsync()
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.Finalize()
Abort trap: 6
Administrators-Mac-mini:~ admin$ 
kai-h commented 6 years ago

Here are the results on a clean 10.12.6 install

Last login: Thu Nov 30 08:48:11 on ttys000
Administrators-Mac-mini:~ admin$ pwsh
PowerShell v6.0.0-rc
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

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

PowerShell credential request
Enter your credentials.
User: admin@example.com
Password for user admin@example.com: ********

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Management.Automation.Remoting.PrioritySendDataCollection.Clear() in /PowerShell/src/System.Management.Automation/engine/remoting/fanin/PriorityCollection.cs:line 158
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.CloseAsync() in /PowerShell/src/System.Management.Automation/engine/remoting/fanin/BaseTransportManager.cs:line 949
   at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.CloseAsync() in /PowerShell/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs:line 1219
   at System.Management.Automation.Remoting.Client.BaseClientTransportManager.Finalize() in /PowerShell/src/System.Management.Automation/engine/remoting/fanin/BaseTransportManager.cs:line 998
Abort trap: 6
Administrators-Mac-mini:~ admin$ 
kai-h commented 6 years ago

This could be related to the issues I was seeing that are documented on #4029 As it stands, PowerShell 6.0.0-rc requires the use of OpenSSL libraries installed by Homebrew

diegoalbuquerque commented 6 years ago

For help.

I had the same problem in a Debian 9 docker container. After read the comments above I saw thet there was some broken linkes libraries and it was because the system libraries are newer than expected. Then , i made some symbolic links and everything ran ok.

root@db70f6f67c51:/usr/lib/x86_64-linux-gnu# ldd /opt/microsoft/powershell/6.0.1/libmi.so

    _linux-vdso.so.1 (0x00007ffd4b7fd000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f86cb670000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f86cb46c000)
    libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007f86cb25e000)
    **libssl.so.1.0.0 =>  not found
    libcrypto.so.1.0.0 => not found**
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f86cac56000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f86cb88d000)
    libaudit.so.1 => /lib/x86_64-linux-gnu/libaudit.so.1 (0x00007f86caa2e000)
    libcrypto.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2 (0x00007f86ca5ca000)
    libcap-ng.so.0 => /lib/x86_64-linux-gnu/libcap-ng.so.0 (0x00007f86ca3c4000)_

root@db70f6f67c51:/opt/microsoft/powershell/6.0.1# cd /usr/lib/x86_64-linux-gnu/ root@db70f6f67c51:/usr/lib/x86_64-linux-gnu# ln -s libssl.so.1.0.2 libssl.so.1.0.0 root@db70f6f67c51:/usr/lib/x86_64-linux-gnu# **ls -l libssl***

-rw-r--r-- 1 root root 738444 Nov 2 11:29 libssl.a lrwxrwxrwx 1 root root 13 Nov 2 11:29 libssl.so -> libssl.so.1.1 lrwxrwxrwx 1 root root 15 Feb 21 17:27 libssl.so.1.0.0 -> libssl.so.1.0.2 -rw-r--r-- 1 root root 431232 Dec 13 22:09 libssl.so.1.0.2 -rw-r--r-- 1 root root 442920 Nov 2 11:29 libssl.so.1.1

root@db70f6f67c51:/usr/lib/x86_64-linux-gnu# ln -s libcrypto.so.1.0.2 libcrypto.so.1.0.0 root@db70f6f67c51:/usr/lib/x86_64-linux-gnu# ldd /opt/microsoft/powershell/6.0.1/libmi.so

    _linux-vdso.so.1 (0x00007ffdde3b4000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4e51539000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4e51335000)
    libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007f4e51127000)
    libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f4e50ebe000)
    libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f4e50a5a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4e506bb000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f4e51756000)
    libaudit.so.1 => /lib/x86_64-linux-gnu/libaudit.so.1 (0x00007f4e50493000)
    libcap-ng.so.0 => /lib/x86_64-linux-gnu/libcap-ng.so.0 (0x00007f4e5028d000)_
TheProdigy20P commented 6 years ago

I was having a similar problem but for me the problem was with the -AllowRedirection Parameter.

If i tried in linux.

$Session = $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection

New-PSSession : [ps.outlook.com] Connecting to remote server ps.outlook.com failed with the following error message : Basic Authorization failed for user bb.admin@billabonggroup.com For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : 2,PSSessionOpenFailed

My Powershell Version

PS /> $PSVersionTable                                                                                                                                               

Name                           Value                                                                                                                               
----                           -----                                                                                                                               
PSVersion                      6.0.2                                                                                                                               
PSEdition                      Core                                                                                                                                
GitCommitId                    v6.0.2                                                                                                                              
OS                             Linux 4.13.0-37-generic #42-Ubuntu SMP Wed Mar 7 14:13:23 UTC 2018                                                                  
Platform                       Unix                                                                                                                                
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                             
PSRemotingProtocolVersion      2.3                                                                                                                                 
SerializationVersion           1.1.0.1                                                                                                                             
WSManStackVersion              3.0       

Same thing in Powershell in windows 10

PS C:\Users\user> $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection

WARNING: Your connection has been redirected to the following URI: "https://ps.outlook.com/PowerShell-LiveID?PSVersion=5.1.16299.251 "

I get a warning of a redirection but I do get the connection succesfully.

My PSversion on Windows 10

PS C:\Users\user> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.251
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.251
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Now running the same command in linux but using the redirected URI we got in windows.

PS /> $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/PowerShell-LiveID?PSVersion=5.1.16299.251" -Credential $O365Cred -Authentication Basic -AllowRedirection                                                                                                                
PS /> $O365Session                                                                                                                                                  

 Id Name            ComputerName    ComputerType    State         ConfigurationName     Availability
 -- ----            ------------    ------------    -----         -----------------     ------------
  6 WinRM6          ps.outlook.com  RemoteMachine   Opened        Microsoft.Exchange       Available

This seems to me the problem is that the allowredirection paratemer is not working properly.

kai-h commented 6 years ago

After installing the latest PowerShell (v6.0.2) this is no longer working for me:

[kai@blackmac ~]$ pwsh
PowerShell v6.0.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/kai> $PSVersionTable                                                                                                             

Name                           Value                                                                                                      
----                           -----                                                                                                      
PSVersion                      6.0.2                                                                                                      
PSEdition                      Core                                                                                                       
GitCommitId                    v6.0.2                                                                                                     
OS                             Darwin 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X...
Platform                       Unix                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                    
PSRemotingProtocolVersion      2.3                                                                                                        
SerializationVersion           1.1.0.1                                                                                                    
WSManStackVersion              3.0                                                                                                        

PS /Users/kai> $UserCredential = Get-Credential                                                                                            

PowerShell credential request
Enter your credentials.
User: admin@example.onmicrosoft.com
Password for user admin@example.onmicrosoft.com: ***********

PS /Users/kai> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection                                                                     
New-PSSession : [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 line:1 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : 1,PSSessionOpenFailed
PS /Users/kai> 
iSazonov commented 6 years ago

@SteveL-MSFT Should we consider this as unstable, as bad UX or as bad documented?

kai-h commented 6 years ago

Is this something that's changed in the latest versions so that Basic auth doesn't work, or is it more than that? I'm happy to do some more testing if required.

SteveL-MSFT commented 6 years ago

The servicing updates to 6.0.0 have not had any changes that affect this. Not sure if there have been any changes on the server side. cc @dantraMSFT

dantraMSFT commented 6 years ago

On MacOS, I do see a regression in 6.0.1 with a consistent ERROR_WSMAN_INVALID_SELECTORS error. I don't see any issues in 6.0.0 and 6.0.2 and libpsrpclient hasn't changed across these releases. The machine hasn't been upgraded to High Sierra yet so that might be contributing.

kai-h commented 6 years ago

My testing was on a Mac that was recently upgraded from macOS 10.12 Sierra to 10.13 High Sierra. I also upgraded PowerShell from whatever version I had previously (likely to be 6.0.0 or 6.0.1) to the latest version 6.0.2. I also updated my MacPorts installation to the latest version and updated all of my ports. I have a symlink for PowerShell from where it expects to find the OpenSSL libraries as installed by Homebrew to where they are installed by MacPorts and this was all working prior to the upgrades for connecting to Office 365

nmguidry72 commented 6 years ago

I have powershell 6.0.2 installed. I've installed MacPorts and created the OpenSSL pkg and installed that. When I try to create $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI https://outlook.office365.com/powershell-liveid/ -Credential $O365Cred -Authenticatin Basic -Allowredirection, and I get the same error of New-PSSession : This parameter set requires WSMan, and no supported WSMan client library was found. $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:x... Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

What do I need to do to fix the issue of WSMan?

MEADITYABHASIN commented 5 years ago

I am new to O365 and PS on Mac. I am facing the same error message here. Would appreciate any help I can get.

Name Value


PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Darwin 17.6.0 Darwin Kernel Version 17.6.0: Tue May 8 15:22:16 PDT 2018; root:xnu-4570.61.1~... Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS /Users/AdityaBhasin> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
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

PS /Users/AdityaBhasin>

System Version: macOS 10.13.5 (17F77)

kai-h commented 5 years ago

Do you have OpenSSL installed with Homebrew? Or, if you are using MacPorts (which I recommend), have you linked the OpenSSL library directory to where PowerShell thinks it should be?

sudo ln -s /opt/local/lib /usr/local/opt/openssl/lib
MEADITYABHASIN commented 5 years ago

WOW! Thank you so much @kai-h I went ahead to run command to update the open SSL with Homebrew and it now seems to work for me. I will update here if I face any new challenge. Thanks again!

ssstonebraker commented 5 years ago

Installing PowerShell v6.0.4 on OSX 10.13.3 fixed the problem for me.

Install Link: https://github.com/PowerShell/PowerShell/releases/download/v6.0.4/powershell-6.0.4-osx.10.12-x64.pkg

iSazonov commented 5 years ago

@kai-h Can you confirm?

NorthernLights commented 5 years ago

Reopening this issue: version 6.1.0 on Mojave is resulting in the same issue when attempting to connect to Office 365.

SteveL-MSFT commented 5 years ago

This is also repro'ing for me with Mojave

kai-h commented 5 years ago

This works for me with 6.0.4 on Mojave with OpenSSL libraries installed via MacPorts, NOT Homebrew.

[kai@blackmac ~]$ pwsh                                                                                                                                              
PowerShell v6.0.4
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/kai> $PSVersionTable                                                                                                                                                     

Name                           Value                                                                                                                                              
----                           -----                                                                                                                                              
PSVersion                      6.0.4                                                                                                                                              
PSEdition                      Core                                                                                                                                               
GitCommitId                    v6.0.4                                                                                                                                             
OS                             Darwin 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64                                     
Platform                       Unix                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                            
PSRemotingProtocolVersion      2.3                                                                                                                                                
SerializationVersion           1.1.0.1                                                                                                                                            
WSManStackVersion              3.0                                                                                                                                                

PS /Users/kai> office365.ps1                                                                                                                                                       

PowerShell credential request
Enter your credentials.
User: admin@example.onmicrosoft.com
Password for user admin@example.onmicrosoft.com: ********

WARNING: The names of some imported commands from the module 'tmp_nlc54neg.nu0' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.                                                                                                                                                                                                                                                ModuleType Version    Name                                ExportedCommands                                                                                                         ---------- -------    ----                                ----------------                                                                                                         Script     1.0        tmp_nlc54neg.nu0                    {Add-AvailabilityAddressSpace, Add-DistributionGroupMember, Add-MailboxFolderPermission, Add-MailboxLocation...}         

PS /Users/kai> 
kai-h commented 5 years ago

This also works for me when I've upgraded to 6.1.0 on Mojave. To reiterate, I am using OpenSSH libraries from MacPorts and have linked them to the location that PowerShell expects to see them.

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

Then, when I run pwsh

[kai@blackmac ~]$ pwsh
PowerShell 6.1.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/kai> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Darwin 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS /Users/kai> office365.ps1

PowerShell credential request
Enter your credentials.
User: admin@example.onmicrosoft.com
Password for user admin@example.onmicrosoft.com: ********

WARNING: The names of some imported commands from the module 'tmp_kllnlbam.5cg' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.                                                                                                                                                                        ModuleType Version    Name                                ExportedCommands                                                                                 ---------- -------    ----                                ----------------                                                                                 Script     1.0        tmp_kllnlbam.5cg                    {Add-AvailabilityAddressSpace, Add-DistributionGroupMember, Add-MailboxFolderPermission, Add-... 

PS /Users/kai> 
SteveL-MSFT commented 5 years ago

Using the MacPorts version of OpenSSL worked for me.

travislikestocode commented 4 years ago

I'm reproducing this on Mojave with Macports OpenSSL: Mac OS Mojave 10.14.5 Powershell 6.2.3

xcode tools are installed. I installed powershell with homebrew.

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Darwin 18.6.0 Darwin Kernel Version 18.6.0: Thu…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I installed openssl using the MS doc instructions via MacPorts:

ws2784:~ travis.brackett$ port installed
The following ports are currently installed:
  openssl @1.1.1d_0 (active)
  zlib @1.2.11_0 (active)

I created the symlink:

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

wsnnnn:~ travbrack$ ls -lha /usr/local/opt/openssl/lib/
total 14496
drwxr-xr-x  16 root  wheel   512B Nov 22 14:39 .
drwxr-xr-x  11 root  wheel   352B Nov 22 13:58 ..
-rw-r--r--   1 root  wheel     0B Oct 20 13:21 .turd_MacPorts
drwxr-xr-x   4 root  admin   128B Nov 22 14:39 engines-1.1
lrwxr-xr-x   1 root  wheel    14B Nov 22 14:28 lib -> /opt/local/lib
-rwxr-xr-x   1 root  admin   2.1M Sep 15 05:22 libcrypto.1.1.dylib
-rw-r--r--   1 root  admin   3.7M Sep 15 05:22 libcrypto.a
lrwxr-xr-x   1 root  admin    19B Sep 15 05:22 libcrypto.dylib -> libcrypto.1.1.dylib
-rwxr-xr-x   1 root  admin   479K Sep 15 05:22 libssl.1.1.dylib
-rw-r--r--   1 root  admin   704K Sep 15 05:22 libssl.a
lrwxr-xr-x   1 root  admin    16B Sep 15 05:22 libssl.dylib -> libssl.1.1.dylib
-rwxr-xr-x   1 root  admin    79K Oct  1  2018 libz.1.2.11.dylib
lrwxr-xr-x   1 root  admin    17B Oct  1  2018 libz.1.dylib -> libz.1.2.11.dylib
-rw-r--r--   1 root  admin    95K Oct  1  2018 libz.a
lrwxr-xr-x   1 root  admin    17B Oct  1  2018 libz.dylib -> libz.1.2.11.dylib
drwxr-xr-x   6 root  admin   192B Nov 22 14:39 pkgconfig
wsnnnn:~ travbrack$ ls -lha /usr/local/opt/openssl/lib
lrwxr-xr-x  1 root  admin    14B Nov 22 14:02 /usr/local/opt/openssl/lib -> /opt/local/lib

I restarted my terminal, and tried enter-pssession:

PS /Users/travbrack> enter-pssession computername
enter-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:1
+ enter-pssession computername
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (computername:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed

Any assistance would be greatly appreciated

jshum commented 4 years ago

Commenting from #10600

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 switching to openssl 1.0.2r worked as well. I had the openssl 1.1 installed through brew as default but they did not work

leeharrison commented 4 years ago

Hi guys,

regarding the openssl version, I forced brew to use ver 1.02 and this fixed my pwsh O365 issues. The commands I ran are ...

brew uninstall openssl; brew uninstall openssl; (to ensure nothing was left lingering around) brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb

Credit : @kensoh

Thanks.

hazardv commented 4 years ago

@leeharrison that worked for me running mojave with pwsh 6.0.4. I tried all previous suggestions and nothing else worked for me.

thepowercoders commented 4 years ago

thanks @leeharrison I've also had this issue on High Sierra with pwsh 6.0.4 and your suggestion has fixed for me too.

kai-h commented 4 years ago

Can we please ensure that PowerShell on macOS doesn't have a hard dependency on an older, and insecure, version of OpenSSL libraries? It is also bad practice to explicitly require that the library is installed by Homebrew with a hardcoded path.

iSazonov commented 4 years ago

Also see https://github.com/PowerShell/PowerShell/issues/11216#issuecomment-608221120

svinuesa commented 4 years ago

Hi guys,

regarding the openssl version, I forced brew to use ver 1.02 and this fixed my pwsh O365 issues. The commands I ran are ...

brew uninstall openssl; brew uninstall openssl; (to ensure nothing was left lingering around) brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb

Credit : @kensoh

Thanks.

This is definitely well working ! Thank you.

mikeyjoel commented 4 years ago

Hi guys,

regarding the openssl version, I forced brew to use ver 1.02 and this fixed my pwsh O365 issues. The commands I ran are ...

brew uninstall openssl; brew uninstall openssl; (to ensure nothing was left lingering around) brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb

Credit : @kensoh

Thanks.

This is working with Catalina 10.15.4

mbonne commented 4 years ago

Hi guys, regarding the openssl version, I forced brew to use ver 1.02 and this fixed my pwsh O365 issues. The commands I ran are ... brew uninstall openssl; brew uninstall openssl; (to ensure nothing was left lingering around) brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb Credit : @kensoh Thanks.

This is working with Catalina 10.15.4

How are you getting this to work without breaking other brew installed tools?? Seems I can only have either or when I tried it. Either roll back openssl version, pwsh works but iperf3 breaks for example.

Name Value


PSVersion 7.0.1 PSEdition Core GitCommitId 7.0.1 OS Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X8… Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

kai-h commented 4 years ago

Can I please just put this out there that downgrading to an older, deprecated and therefore insecure version of OpenSSL is not a real solution.

Apple have already got a heap of different versions of the OpenSSL libraries installed on macOS.

Why does PowerShell on macOS have hardcoded paths to the libraries, instead of searching the system library path.

In the /usr/lib folder we have half a dozen different versions that are sitting there waiting to be used. /usr/lib/libssl.0.9.8.dylib /usr/lib/libssl.dylib /usr/lib/libssl.35.dylib /usr/lib/libssl.0.9.7.dylib /usr/lib/libssl.43.dylib /usr/lib/libssl.46.dylib /usr/lib/libssl.44.dylib

mikeyjoel commented 4 years ago

Can I please just put this out there that downgrading to an older, deprecated and therefore insecure version of OpenSSL is not a real solution.

Apple have already got a heap of different versions of the OpenSSL libraries installed on macOS.

Why does PowerShell on macOS have hardcoded paths to the libraries, instead of searching the system library path.

In the /usr/lib folder we have half a dozen different versions that are sitting there waiting to be used. /usr/lib/libssl.0.9.8.dylib /usr/lib/libssl.dylib /usr/lib/libssl.35.dylib /usr/lib/libssl.0.9.7.dylib /usr/lib/libssl.43.dylib /usr/lib/libssl.46.dylib /usr/lib/libssl.44.dylib

I hope you understand that those are older releases of OpenSSL. New release is v1.1.0 released August 25, 2016 - Version 0.9.8 was released July 5, 2005. I ended up switching to Linux anyways since I can't deal with the implementation of OpenSSH on so many Windows servers and maintain them, but still looking forward on how kerberos will be supported for PSCore in future releases and if there is any care for it on macOS.

iSazonov commented 4 years ago

@mikeyjoel Please create new issue and describe remoting scenarios you want to work.

mikeyjoel commented 4 years ago

@mikeyjoel Please create new issue and describe remoting scenarios you want to work.

No need for me to create a new issue since an issue was already created: #3708

On RHEL/Centos or Debian/Ubuntu Distribution you'll need the following packages: krb5-workstation krb5-devel gssntlmssp (requires epel-release to be installed beforehand) powershell

Which are available by default for each Linux distribution. I'm bringing this up because its very common that you won't be just managing Office365 but also Windows Servers in your environment.

kai-h commented 4 years ago

Can I please just put this out there that downgrading to an older, deprecated and therefore insecure version of OpenSSL is not a real solution. Apple have already got a heap of different versions of the OpenSSL libraries installed on macOS. Why does PowerShell on macOS have hardcoded paths to the libraries, instead of searching the system library path. In the /usr/lib folder we have half a dozen different versions that are sitting there waiting to be used. /usr/lib/libssl.0.9.8.dylib /usr/lib/libssl.dylib /usr/lib/libssl.35.dylib /usr/lib/libssl.0.9.7.dylib /usr/lib/libssl.43.dylib /usr/lib/libssl.46.dylib /usr/lib/libssl.44.dylib

I hope you understand that those are older releases of OpenSSL. New release is v1.1.0 released August 25, 2016 - Version 0.9.8 was released July 5, 2005. I ended up switching to Linux anyways since I can't deal with the implementation of OpenSSH on so many Windows servers and maintain them, but still looking forward on how kerberos will be supported for PSCore in future releases and if there is any care for it on macOS.

I am well aware that these are older OpenSSL libraries - however as pwsh currently only works with older libraries, they are already installed on macOS.

jborean93 commented 4 years ago

So I'm not sure where to share this but I've been recently playing around with OMI to try and get it working against a newer version of OpenSSL (1.1.0) as well as Kerberos auth (and hopefully NTLM as well) on a Mac. There are a few bugs that I've fixed up on a local build but it's definitely possible to get it working and I am planning on creating a blog post/guide on helping people do the same to get PSRemoting through WinRM on their non-Windows hosts.

I was wondering how interested the PowerShell team is in trying to incorporate those changes into their compiled build of OMI that they include in their release. I'm planning on trying to merge them into the OMI repo but I'm not optimistic they will actually make it in. The OpenSSL fix should also allow them to drop the requirement on OpenSSL 1.0.0 that they have documented in their install steps as it looks like it was only the PSRP client stuff that required those libraries.

This seemed to be the longest thread I could find on this problem so I thought it best to post here. Happy to create a new issue to compile the various problems and workarounds/fixes that I've found so we can document it properly for others wanting to try it out.