Skip to content

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

Closed
@kai-h

Description

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                                                                    

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifOS-macOSResolution-FixedThe issue is fixed.WG-RemotingPSRP issues with any transport layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions