skharia
skharia

Reputation: 1

azure powershell generating Account key error

I want to create a container through Windows PowerShell and therefore try to obtain the account key via

$storageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName | %{ $_.Key1 }

Getting the error

New-AzureStorageContext : Cannot validate argument on parameter 'StorageAccountKey'. The argument is null or empty. Provide an argument that is not null or empty, and then try the 
command again. 

Upvotes: 0

Views: 570

Answers (1)

DAXaholic
DAXaholic

Reputation: 35358

This should work

$storageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName | ? { $_.KeyName -eq 'Key1' } | % { $_.Value }

The problem is that the result is not a hashtable but a .NET generic list so it is not possible to access the value directly via the key name. .NET generic list instead of hashtable

Upvotes: 1

Related Questions