0

Unable Connect Exchange Remote PowerShell Using Windows 10 Anniversary Update

After updating Windows 10 you may be unable to connect to a remote PowerShell session.  This is an issue for versions of Exchange 2010 onwards as we use remote PowerShell for administration.  The same applies for Exchange Online in Office 365.  Note that directly loading the Exchange PSSnapin is not supported apart from a limited number of documented scenarios, for example this is one of them.  For more details on how Exchange uses PowerShell please read this series of posts.

How To Maximize Exchange Administrator Productivity With PowerShell–Part 1

How To Maximize Exchange Administrator Productivity With PowerShell–Part 2

How To Maximize Exchange Administrator Productivity With PowerShell–Part 3

 

Let’s look at a quick example of what you may see on a Windows 10 machine when trying to connect to Exchange Online.

Update 26-8-2016: See also PowerShell DSC and implicit remoting broken in KB3176934

Update 2-9-2016: An update to correct the issue has been released.  Please refer to the note in the CU.  To fix this issue, download update 3176938 from the Microsoft Update Catalog website.

Windows 10 Anniversary Edition Repro

Windows PowerShell was launched from its regular shortcut.  In the below example I’m using the simple connection script to connect to Exchange Online.  It will prompt for credentials and then connect.

Connecting to Exchange Online Using Remote PowerShell

All good so far.  After entering the credentials we get the regular warning about the redirection, this is expected so don’t panic!

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

However the red text is never a good thing.  Trying to import the PSSession has failed.  Bummer.

Connecting to Exchange Online Using Remote PowerShell - Could Not Import PSSession

For the search engines, the detailed error is:

Import-PSSession : Could not load type ‘System.Management.Automation.SecuritySupport’ from assembly
‘System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’.
At C:ScriptsConnect-EXO.PS1:6 char:18
+ $ImportResults = Import-PSSession $Session
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Import-PSSession], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportPSSessionCommand

 

Did the connection really fail?  Let’s see where it got to.  Trying to use Get-Mailbox fails, so that cmdlet is not available to us.

Connecting to Exchange Online Using Remote PowerShell - No Exchange Cmdlets

What about the script module, was that downloaded and created?  We will check using Get-Module.

Connecting to Exchange Online Using Remote PowerShell - No Exchange Script Module

Nope there is no script module which is used to contain the Exchange cmdlets.

For comparison, the below is from a Windows Server 2012 R2 server.  Note the script module which is underlined:

Exchange Online Remote PowerShell - Script Module Present

That is where the Exchange cmdlets are represented as client side functions.  No script module, no function and therefore no cmdlets are available.

 

Windows 10 PowerShell Details

If we look at the version of PowerShell which is loaded when the Windows PowerShell start menu shortcut is used, we can see that it is a new and updated version of PowerShell.  The PSVersion is reported as 5.1.14393.82.

Windows 10 Anniversary Edition PSVersion Table

 

Workaround

While the issue is worked upon by the teams involved, there is a quick workaround.

Rather than using the default instance of PowerShell, we can go old skool and use a downlevel version.  The easiest way is to use the run box to start PowerShell up as version 2.0.  You can click Start, then Run and enter the command.  Alternatively I love to use the Windows Key + R as a keyboard shortcut to get to the Run box.

In the Run box enter:

PowerShell.exe -Version 2.0

 

Then we connect in the normal way.  In the below example, note that I am showing the OS version and the PowerShell version to prove there is no funny business.

Workaround on Windows 10 Anniversary Edition - Rocking It Old School With PowerShell Version 2.0

 

Cheers,

Rhoderick

Rhoderick Milne [MSFT]

Leave a Reply

Your email address will not be published. Required fields are marked *