powershell login error

ABBA 46 Reputation points
2021-02-05T01:31:45.19+00:00

hi all
i am new to powershell and azure world. i am trying to login to my office365 azure using powershell. my admin account is MFA enabled. i am using connect-azuread command. i get the prompt to enter username/password and then approve the request using authenticator. but after approval from authenticator app i always get the error
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.)
Connect-AzureAD: Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

can you anyone please help me with this. what am i doing wrong here.

regards

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,361 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,447 questions
{count} votes

7 answers

Sort by: Most helpful
  1. Vasil Michev 95,096 Reputation points MVP
    2021-02-05T08:01:24.147+00:00

    If you are running this on PowerShell 7+/Core, you need to import the module in compatibility mode:

    Import-Module AzureAD -UseWindowsPowerShell
    
    11 people found this answer helpful.

  2. Dilgam Sharifov 26 Reputation points
    2021-04-18T21:30:35.947+00:00

    Thank you, it worked for me with "Import-Module AzureAD -UseWindowsPowerShell" in VS Studio.

    1 person found this answer helpful.

  3. Daniele Ciribifera 6 Reputation points
    2022-08-24T09:46:47.067+00:00

    Hi all,

    I can confirm that with PS 5 the module works.
    Thank you all.

    in brief:

    C:\> powershell.exe -version 5.1
    PS> Install-Module AzureAD
    PS> Import-Module AzureAD
    PS> Connect-AzureAD

    regards
    D

    1 person found this answer helpful.
    0 comments No comments

  4. Tommy Svensson 6 Reputation points
    2022-11-11T11:19:45.707+00:00

    This does not work still.
    Version 7.3.0 of powershell and 2.0.2.140 of AzureAD powershell module.

    I get the same error trying to run "Connect-PimService".

    1 person found this answer helpful.
    0 comments No comments

  5. Owen Murr 151 Reputation points
    2021-03-09T09:04:43.157+00:00

    This should no longer need the -usewindowspowershell.

    Which version of the AzureAD module do you have installed, and have you updated to the latest stable version of Powershell core/7?