Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Connect-AzAccount The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded

While connecting to Azure using Powershell with Connect-AzAccount cmdlet I was receiving below error. As troubleshooting steps I tried to update/install Az module from online Microsoft PowerShell repository with -Force and -AllowClobber parameters, tried to Import Module Az, Az.Accounts on PowerShell v5.1 and 7, but with no success and error persisted.

Connect-AzAccount
Connect-AzAccount : The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded. For more information, run 'Import-Module Az.Accounts'.
At line:1 char:1
+ Connect-AzAccount
+~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Connect-AzAccount:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

I tried using old cmdlet Login-AzAccount but I receiving some other error.

Login-AzAccount
Connect-AzureRmAccount: Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version 4.0.0.0, Culture neutral, PublicKeyToken b77a5c561934e089'.

In the last I figured out this issue was due to conflict with old AzureRm module exist and new Az module. I uninstalled AzureRm module with below command, I uninstalled it from Powershell v7 and Powershell 5.1 version.

Uninstall-AzureRm
WARNING: Running this cmdlet in PowerShell Core will only remove the modules from PowerShell Core. Please rerun this cmd let in a PowerShell 5.1 session to remove the modules from PowerShell 5.1.

After removal of old modules, I imported Az Module and tested the Connect-AzAccount cmdlet it redirected me to url of Microsoft Azure log in page, After authentication login was successful.

Import-Module -Name Az
Connect-AzAccount

Useful Articles
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
Powershell Azure Az module Install-Package cannot convert value 2.0.0-preview to type system.version

Part 1: Create and deploy a website with Microsoft Azure web app service plan
Part 2: Configure a custom domain in Azure Web Apps
Part 3: Uploading to Azure Web Apps Using FTP
Part 4: Add and manage TLS SSL certificates on Azure Web App

 



This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here

Share the post

Connect-AzAccount The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded

×

Subscribe to Tales From Real It System Administrators World And Non-production Environment

Get updates delivered right to your inbox!

Thank you for your subscription

×