1

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

Jumbo
  • 35
  • 8

2 Answers2

0

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
Mike Kennedy
  • 374
  • 2
  • 6
0

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} 
Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60