Shiangoli on Fri, 13 May 2016 14:08:05

Hi All,

I've created a powershell script that creates an Azure Storage Account (Not Classic). The script also creates containers inside the storage account and uploads files as blobs. This all works well however the next stage is to retrieve the access key for the storage account such that I can then use this to create the Azure Storage Credential for an Azure Data Warehouse deployment. However all the online documentation for the following does not work. I'm using Azure 1.4 cmdlets.

All works ok until the execution of the command Get-AzureStorageKey. I've highlighted in bold. The error I get 

is below suggesting the storage account was not found however the storage account was successfully created as part of the execution of the script upstream. It would appear this command is perhaps only suitable for classic storage? Is there an alternative cmdlet for post classic storage? Or am I doing something wrong? Any help would be greatly appreciated. Thank you

Get-AzureStorageKey : ResourceNotFound: The storage account 'storagedeploytest3' was not found.
OperationID : 'b98b66ef2dc5a53186d0fadd918d6df1'
At line:1 char:1
+ Get-AzureStorageKey -StorageAccountName "storagedeploytest3"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureStorageKey], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.StorageServices.GetAzureStorageKeyComm

The code snipet is illustrated below::


Select-AzureRmSubscription -SubscriptionId $SubscriptionID


# Create a new storage account.
if (!(Test-AzureName -Storage $StorageAccountName))
New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName -Location $Location -Type $StorageAccountType
Write-Host "Storage Account Created" 

Write-Host "Storage account $StorageAccountName already exists" 

Set-AzureRmCurrentStorageAccount -StorageAccountName $StorageAccountName -ResourceGroupName $ResourceGroupName

$StorageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary
#Return the storage account key
Return $StorageAccountKey 



Shiangoli on Fri, 13 May 2016 17:25:18

Hi All,

I found the alternative command below which returns all the keys. However I've had no luck returning the primary key. The example below returns both keys

Get-AzureRMStorageAccountKey -ResourceGroupName "Group" -Name "storagedeploytest" | Where-Object {$_.KeyName -eq 'key1'}

Also when you assign the above to a variable in your script as illustrated below


= Get-AzureRMStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName | %{ $_.key1 }

and then execute it will still prompt for the group and storage account name even though the values have been correctly set

cmdlet Get-AzureRmStorageAccountKey at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)

iisworks on Sat, 14 May 2016 15:11:00

I also noticed 1.4.0 broke this, I changed the .Key1 bit to:

$StorKey=(Get-AzureRmStorageAccountKey -Name $saName -ResourceGroupName $RgName)[0].Value