Not able to execute Get-AzStorageAccount, though module is installed.

Kothai Ramanathan (SC-ALT) 51 Reputation points Microsoft Employee
2024-02-06T12:27:34.8466667+00:00

Code:

	$saContext = (Get-AzStorageAccount -ResourceGroupName $primaryResourceGroupName -Name $StorageName).Context               

    Write-Output "Get-AzStorageAccount executed: $saContext" 
    Write-Output "Table Name is $DRComponentsState"

    $table = (Get-AzStorageTable -Name $DRComponentsState -Context $saContext).CloudTable
    Write-Output "Get-AzStorageTable executed: $table"

Output: Get-AzStorageAccount executed: Microsoft.WindowsAzure.Commands.Common.Storage.LazyAzureStorageContext Table Name is DRComponentsState Ran into an issue: The term 'Get-AzStorageTable' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Concern: Both Get-AzStorageAccount and Get-AzStorageTable are in the same module Az.Storage. This module is installed in my automation account. Why is Get-AzStorageAccount working and Get-AzStorageTable giving an error?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,368 questions
{count} votes

Accepted answer
  1. tbgangav-MSFT 10,426 Reputation points Moderator
    2024-02-06T13:39:25.7566667+00:00

    Hi @Kothai Ramanathan (SC-ALT) , The error says that the Get-AzStorageTable is not a recognized cmdlet so you would have to make sure the right version of the Az.Storage module is imported in your Azure Automation account which contains Get-AzStorageTable cmdlet as part of it. In my testing, I see the Get-AzStorageTable cmdlet is present as part of Az.Storage module current version 6.11 so you may check which version of Az.Storage module you have in your Azure Automation account and update it to the 6.11 version as shown below. Note that it has dependency of having Az.Accounts module of version >= 2.15.1 so make sure you meet the dependency first and then import the Az.Storage module versioned 6.11, may be as illustrated in below screenshots. User's image

    User's image

    User's image

    User's image

    Once the dependencies and the required modules are successfully imported, execute your runbook with below command and see if you are getting an output. If yes, then you are good to use Get-AzStorageTable cmdlet in your runbook.

    Get-Module Az.Storage | ?{$_.ExportedCommands.Keys -like '*Get-AzStorageTable*'} 
    

    If this didn't help, execute below command in a runbook and see if you get output with multiple modules. The ask is because we wanted to make sure that cmdlet doesn't exist in another module along with Az.Storage module. If that's the case, then Automation can't resolve the cmdlet and hence the error.

    Get-Module | ?{$_.ExportedCommands.Keys -like '*Get-AzStorageTable*'} 
    
    

    References:


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.