Forum Discussion

M3Jota's avatar
M3Jota
Copper Contributor
Nov 12, 2020

Unable to Connect to ExchangeOnline

So we have MFA enabled on our Office 365 accounts. From my Windows 10 computer, I can connect to the ExchangeOnlineManagement module without issue. However, on my DC I installed Powershell 7.0.3, then successfully installed the ExchangeOnlineManagement module. I can successfully import the module, however when I attempt to connect to it I get the below error. Any ideas?

 

PS C:\Windows\System32> Connect-ExchangeOnline -UserPrincipalName MyUsername -ShowProgress $true

----------------------------------------------------------------------------
The module allows access to all existing remote PowerShell (V1) cmdlets in addit
ion to the 9 new, faster, and more reliable cmdlets.

|--------------------------------------------------------------------------|
| Old Cmdlets | New/Reliable/Faster Cmdlets |
|--------------------------------------------------------------------------|
| Get-CASMailbox | Get-EXOCASMailbox |
| Get-Mailbox | Get-EXOMailbox |
| Get-MailboxFolderPermission | Get-EXOMailboxFolderPermission |
| Get-MailboxFolderStatistics | Get-EXOMailboxFolderStatistics |
| Get-MailboxPermission | Get-EXOMailboxPermission |
| Get-MailboxStatistics | Get-EXOMailboxStatistics |
| Get-MobileDeviceStatistics | Get-EXOMobileDeviceStatistics |
| Get-Recipient | Get-EXORecipient |
| Get-RecipientPermission | Get-EXORecipientPermission |
|--------------------------------------------------------------------------|

To get additional information, run: Get-Help Connect-ExchangeOnline or check htt
ps://aka.ms/exops-docs

Send your product improvement suggestions and feedback to exocmdletpreview@servi
ce.microsoft.com. For issues related to the module, contact Microsoft support. D
on't use the feedback alias for problems or support issues.
----------------------------------------------------------------------------

New-ExoPSSession: C:\Users\jwcitadmin\Documents\PowerShell\Modules\ExchangeOnlin
eManagement\2.0.3\ExchangeOnlineManagement.psm1:426
Line |
426 | . PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro
.
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Could not load type 'System.Security.Cryptography.SHA256Cng' from
| assembly 'System.Core, Version=4.0.0.0, Culture=neutral,
| PublicKeyToken=b77a5c561934e089'..

  • farismalaeb's avatar
    farismalaeb
    Steel Contributor

    M3Jota 

    I am not totally sure, but based on some reading I did there is a compatibility issues between Powershell 7 and ExchangeOnline, even though its almost 1 year post, but not sure if MS fix it or not.

     

    https://github.com/PowerShell/PowerShell/issues/11070

     

    I have the same case, and I am using Powershell 5.1 to manage Exchange Online, as it seems that Powershell Core is not compatible with the module.

     

    even in Windows Event Log I have the following Warning:

     

    Error Message = Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..
    Fully Qualified Error ID = System.Exception,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession


    Context:
    Severity = Warning
    Host Name = ConsoleHost
    Host Version = 7.1.0
    Host ID = d1434fc6-2c2d-4b64-8ca4-38ca5f6668c9
    Host Application = C:\Program Files\PowerShell\7-preview\pwsh.dll -WorkingDirectory ~
    Engine Version = 7.1.0
    Runspace ID = d84be782-d5d3-413a-b7c1-a2ab71ab9e4f
    Pipeline ID = 75
    Command Name = New-ExoPSSession
    Command Type = Cmdlet
    Script Name = C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.3\ExchangeOnlineManagement.psm1
    Command Path =
    Sequence Number = 8
    User = 266517A\User390
    Connected User =
    Shell ID = Microsoft.PowerShell


    User Data:

     

     

    ---------------------------

    If you find this answer helpful, Please click on Best Response and give like

     

    • VasilMichev's avatar
      VasilMichev
      MVP

      farismalaeb is correct, the ExO V2 module doesnt support PowerShell 7/Core yet. A preview version is available and GA should follow in the coming weeks/months.

      • Lu_Li's avatar
        Lu_Li
        Copper Contributor

        Hi VasilMichev , i am facing the same issue to use powershell script 7 to connect to ExchangeOnline. 

        Just wondering if you know what is current progress ? Thanks. 

  • kantaprasad27's avatar
    kantaprasad27
    Copper Contributor

    M3Jota 

     

    I have removed Powershell 7.1 (using control panel) and "Connect-ExchangeOnline" problem solved when my computer is running with Powershell 5.1.

     

    Please mark this post if its a solution for your problem too.

     

     

  • This also works, in PowerShell 7 you can use the -UseWindowsPowerShell parameter when importing modules which are not compatible with PowerShell 7 but do work in PowerShell 5.

    C:\Users\HarmV> Import-Module ExchangeOnlineManagement -UseWindowsPowerShell
    WARNING: Module ExchangeOnlineManagement is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.
    C:\Users\HarmV> Connect-ExchangeOnline

    ----------------------------------------------------------------------------
    The module allows access to all existing remote PowerShell (V1) cmdlets in addition to the 9 new, faster, and more reliable cmdlets.

    |--------------------------------------------------------------------------|
    | Old Cmdlets | New/Reliable/Faster Cmdlets |
    |--------------------------------------------------------------------------|
    | Get-CASMailbox | Get-EXOCASMailbox |
    | Get-Mailbox | Get-EXOMailbox |
    | Get-MailboxFolderPermission | Get-EXOMailboxFolderPermission |
    | Get-MailboxFolderStatistics | Get-EXOMailboxFolderStatistics |
    | Get-MailboxPermission | Get-EXOMailboxPermission |
    | Get-MailboxStatistics | Get-EXOMailboxStatistics |
    | Get-MobileDeviceStatistics | Get-EXOMobileDeviceStatistics |
    | Get-Recipient | Get-EXORecipient |
    | Get-RecipientPermission | Get-EXORecipientPermission |
    |--------------------------------------------------------------------------|

    To get additional information, run: Get-Help Connect-ExchangeOnline or check https://aka.ms/exops-docs

    Send your product improvement suggestions and feedback to Email address removed. For issues related to the module, contact Microsoft support. Don't use the feedback alias for problems or support issues.
    ----------------------------------------------------------------------------
    • BHK423542353451250's avatar
      BHK423542353451250
      Copper Contributor

      Hi,

      I've been struggling for more than 2 hours just to be able to get a simple user list from an Office 365 distribution list. I've installed PowerShell, downloaded a couple of modules, and at the end of the day still unable to get this fu$$^^ù$ user list. Just kill me guys, I don't understand why the online version offers to download a .csv file of all distribution lists, but not members (?????????). Just a non sens. Never seen a such environment leading to a so huge waste of time. Congrats Microsoft.

Resources