Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Connect-AzureAD: One or more errors occurred. Could not load type 'System.Security.Cryptography.SHA256Cng'

While working on AzureAD (Azure Active Directory) with PowerShell module I was received below errors and my scripts where failing. I updated AzureAD module with Update-Module command to latest one but it was still throwing errors. After few testing I checked PowerShell version, it was latest PowerShell Core version 7.1.3 and found AzureAD module is not compatible with it.

Microsoft azuread import-module system.security.cryptography.sha256Cng connect-Azuread $psversiontable psversion assembly system.core publickeytoken error occurred .png

❯ Import-Module AzureAD

❯ Connect-AzureAD
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'.

$PSVersionTable

As I found AzureAD is not compatible with PowerShell v7.x.x, Next step In order to use AzureAD module I opened PowerShell Desktop version 5.1 and Installed AzureAD module on it from online PSGallary. Then loaded/Imported module into PowerShell and tested connecting to Azure Active Directory, It succeeded. To check further fetched one user details from AzureAD all was good.

Microsoft AzureAD azure active directory $PSVersionTable Install-Module AzureAD -scope currentuser import-module connect-azuread get-azureaduser filter.png

$PSVersionTable 
     PSVersion: 5.1

❯ Install-Module AzureAD -Scope CurrentUser
     Untrusted Repository
     You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the module from 'PSGallary'?
     [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

❯ Import-Module AzureAD

❯ Connect-AzureAD
     Account   Environment    TenantID                               TenantDomain     AccountType
     -------   -----------    --------                               ------------     -----------
     janvi     AzureCloud     3b80xxxx-xxxx-xxxx-xxxx-xxxxxxxxxx     vcloud-lab.com   User

❯ Get-AzureADUser -Filter "DisplayName eq 'janvi'"
     ObjectId                             DisplayName UserPrincipalName  UserType
     --------                             ----------- -----------------  --------
     38638e40-4971-xxxx-971d-2ee1f40724eb Janvi       janvi@vcloud-lab.com Member

Useful articles
Microsoft Azure Rest API using PowerShell Part 2
Azure azcopy login error Selected user account does not exist in tenant 'Microsoft Services' and cannot access the application '579a7132-0e58-4d80-b1e1-7a1e2d337859'
Create and manage Azure budgets
Connect-AzAccount The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded
Microsoft Azure Rest API using PowerShell
How to switch to other Azure AD tenant using PowerShell and Azure CLI
Creating a new user in Azure AD using oneliner PowerShell and Azure CLI

Go Back

Comment

Blog Search

Page Views

12056237

Follow me on Blogarama