Get-AzureAccount is not working in Az modules

834 Views Asked by At

Get-AzureAccount is not working in Az modules .It is giving below error :

Get-AzureAccount : The 'Get-AzureAccount' command was found in the module 'Azure', but the module could not be loaded. For more information, run 'Import-Module Azure'.
+     Get-AzureAccount | ForEach-Object { Remove-AzureAccount $_.ID -Fo ...
+     ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-AzureAccount:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

This Command was working in AzureRM modules as AzureRm is depricating , we need to change all commands to Az modules.

Kindly Help! Thanks in advance

2

There are 2 best solutions below

0
Mike Kennedy On

To login to Azure With Az the command is:

Connect-AzAccount

Install PowerShell Core 7 and install Az this way you can run Both AzureRm and Az

Uninstall-AzureRm

Find-Module -Name Az | Install-Module -AllowClobber
0
Ivan Glasenberg On

If you have Az module installed, you should use Get-AzContext instead of Get-AzureAccount.

And I see you also used Remove-AzureAccount, but in Az module, you should use Remove-AzContext instead.

The sample code looks like below:

Get-AzContext | ForEach-Object { Remove-AzContext -Name $_.name -Force}