0
votes

I logged in using an application account(service principle) then ran Get-AzureStorageKey -StorageAccountName myclassicStorageAccount and got: this error: Get-AzureStorageKey : No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription. but when I run Select-AzureSubscription -Default , it told me this sub doesn't exist, even though this account is owner role for that but.

Please help. Thanks.

1

1 Answers

1
votes

In fact, if you login your account with service principal, you could not use classic Power Shell cmdlet.

You could use Azure Rest API to get storage account access key, you could check this answer. You could use the following power shell.

Invoke-AzureRmResourceAction -ResourceId "/subscriptions/*******/resourceGroups/stlvm/providers/Microsoft.ClassicStorage/storageAccounts/stlsac"  -Action "listKeys" -ApiVersion "2016-11-01" -Force

You could get the resource id on Azure Portal.

enter image description here

I test in my lab, it works for me.

enter image description here

Update:

You could use Get-AzureRmResource to get classic storage account resource group.

##`stlsac` is my classic storage account name, replace it
$storage = Get-AzureRmResource | Where {$_.ResourceType -eq "Microsoft.ClassicStorage/storageAccounts" -and $_.ResourceName -eq "stlsac"}

Invoke-AzureRmResourceAction -ResourceName stlsac -ResourceType Microsoft.ClassicStorage/storageAccounts -ResourceGroupName $storage.ResourceGroupName -Action "listKeys" -ApiVersion "2016-11-01" -Force