Menu

Virtual Geek

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

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.

Microsoft Azure connect-azaccount az.accounts module import-module the command was found in module cannot found module cannot be loaded

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.

Microsoft azure az module login-azaccount connect-azurermaccount cound not load type 'System.Security.Cryptography.SHA256Cng' from assembly system.core culture neutral publickeytoken connect-azaccount.png

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.

Microsoft azure powershell uninstall-azurerm warning running this cmdlet in powershell core will only remove the modules let in powershell 5.1 session to remove module.png

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

Microsoft Azure Powershell Import-Module -name Az connect-AzAccount subscriptionname tenantId Environment AzureCloud authentication Complete sign in password code verify.png

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

Azure web apps, app service plan, paas platform as a service, domain name ssl website hosting microsoft iis nginx windows apache httpd.PNG

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

 

Go Back

Comment

Blog Search

Page Views

11276102

Follow me on Blogarama