Powershell: Connect-AzureAD not working with Powershell 7.1.0-preview.1 - Could not load type 'System.Security.Cryptography.SHA256Cng'

Created on 31 Mar 2020  路  9Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

Run the script below
Login using the pop-up window
The exception below is logged in the console

install-module azuread
import-module azuread
$ctx = Get-AzContext
Connect-AzureAD -TenantId $ctx.Tenant.Id -AccountId $ctx.Account.Id 

Expected behavior

Login succeeds and the user is able to query the AAD

Actual behavior

```The following exception is thrown:

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'.


# Environment data

<!-- provide the output of $PSVersionTable -->

```Name                           Value
----                           -----
PSVersion                      7.1.0-preview.1
PSEdition                      Core
GitCommitId                    7.1.0-preview.1
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue-Question Resolution-Answered

Most helpful comment

@MaximoTrinidad
Your comment was not very helpful, because it contains incorrect and inaccurate statements.

Azure PowerShell team is not responsible for AzureAD module.

With a little help from the -UseWindowsPowerShell parameter, you can now import and use the AzureAD module in #PowerShell 7.
ERfLm0TWsAAckb9
(This is an old screenshot, but it works with the stable PowerShell 7 too.)

All 9 comments

See #11070

@iSazonov I dont see how this resolves the issue. Upgrading to PS 7 breaks this module. Until PS7 is fixed, how can this be resolved?

SHA256Cng is not supported in .Net Core. We can fix nothing in PowerShell Core. You should report the issue in AzureAD module repository.

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

@pmozbert

Just an FYI

All azure modules issues goes to the Azure Github repo: https://github.com/Azure/azure-powershell

Also, any Azure module from the PowerShell Gallery that doesn't start with Az.* means that's a Windows-specific module and could not work in PowerShell 7.

Only the Az.* modules can work with PowerShell Core.

Keep in mind, because PowerShell 7 allows compatibility with Windows modules, this doesn't mean that it will work. This is why it has to be reported to the proper repo area.

Hope this helps!
:)

GitHub
Microsoft Azure PowerShell. Contribute to Azure/azure-powershell development by creating an account on GitHub.

If some Azure modules are windows-specific, and if windows-specific modules cannot work on powershell 7, then that would mean that users of Azure powershell are stuck with the older powershell. That's not great. Also, the azure powershell extension for vscode seems to be broken for pre-7 powershell. So i have to develop with 7, and then run in 5.

@pmozbert

I understand your frustration!

This is the reason why Windows PowerShell will not go away any time soon.
The Azure PowerShell team is working hard to get things working with PowerShell 7.

Think of it as PowerShell as a language. All the investment in learning PowerShell is not lost and the difference between the old and new one are minimal.

Reporting the issue in their repo help speed up the process to get this done, and the best... you get a quick interaction with both the team and the community to help with the issue.

Hang in there!

@MaximoTrinidad
Your comment was not very helpful, because it contains incorrect and inaccurate statements.

Azure PowerShell team is not responsible for AzureAD module.

With a little help from the -UseWindowsPowerShell parameter, you can now import and use the AzureAD module in #PowerShell 7.
ERfLm0TWsAAckb9
(This is an old screenshot, but it works with the stable PowerShell 7 too.)

Thanks @alexandair

I don't think my statement was that incorrect. Direct him to the PowerShell Azure team is the best way to help him find the answer.

Sample provided truly helps but still is just a bandaid. This is not the place to post the issue, as this is not a PowerShell 7 issue. It needs to be addressed to who's responsible for this module.

The documentation don't provide any information about what version of Powershell this version runs on:
https://docs.microsoft.com/en-us/powershell/module/Azuread/?view=azureadps-2.0

@pmozbert

I should have done a little more research. In the PowerShell Gallery:
https://www.powershellgallery.com/packages/AzureAD/2.0.2.76

You can reach out to the Module owner via email.

I hope this will help you!

Azure Active Directory V2 General Availability Module. This is the General Availability release of Azure Active Directory V2 PowerShell Module. For detailed information on how to install and run this module from the PowerShell Gallery including prerequisites, please refer to https://msdn.microsoft.com/powershell/gallery/readme
Was this page helpful?
0 / 5 - 0 ratings