11

I am trying to set Azure Rm Subscription (Get-AzureRMSubscription) CurrentStorageAccount to a particular arm storage account (Get-AzureRmStorageAccount) and I am not able to find a cmdlet that does that.

With regular old azure cmdlets I am able to do following to set CurrentStorageAccount as

$subscription = Get-AzureSubscription
Set-AzureSubscription -SubscriptionName $subscription.SubscriptionName -CurrentStorageAccountName "somestorageaccount"

Get-AzureSubscription | select * 

This set's it. But I cannot do this inside arm cmdlets.

Another thing that is confusing is that I am using the same subscription eg. Visual Studio Enterprise. And using both arm and regular cmdlets get-azuresubscription I get the same subscription but why is one showing -CurrentStorageAccount and another subscription not showing -CurrentStorageAccount.

Mitul
  • 9,734
  • 4
  • 43
  • 60

4 Answers4

11

To set the default RM subscription for the current session in PowerShell use

Get-AzureRmSubscription –SubscriptionName "MyFavSubscription" | Select-AzureRmSubscription

and to set the default RM storage context for the current session

Set-AzureRmCurrentStorageAccount –ResourceGroupName "MyFavResourceGroup" `
                                 –StorageAccountName "MyFavStorageAccountName"
NER1808
  • 1,829
  • 2
  • 33
  • 45
  • How do you know if piping the result to Select-AzureRMSubscription is setting the "default" versus the "current" subscription? I couldn't find the answer here https://learn.microsoft.com/en-us/powershell/module/azure/select-azuresubscription?view=azuresmps-4.0.0 – successhawk Feb 13 '18 at 22:16
  • By the looks of it, if you don't specify -default or -current than both are set. If you only want to set one or other then add the flag. – NER1808 Mar 21 '18 at 12:08
  • @Mitul If this is the answer to your question please mark it as such – NER1808 Sep 11 '18 at 19:24
2

First, you must set your default subscription.

$SubscriptionName = "MyDefaultSubscription"
Select-AzureSubscription -SubscriptionName $SubscriptionName –Default

In other cases, you can set your default subscription location.

# For example, South Central US
$Location = "South Central US"

Then get your storage account name/s

$StorageAccountName = (Get-AzureStorageAccount)[0].label

Notice the number zero? It indicates the numbering of your storage. The numbering starts with 0. If you use the command Get-AzureStorageAccount, it will list all of your (classic) storage accounts. For that you can choose your desired storage.

Then lastly, set your default storage account.

Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccountName $StorageAccountName
Lëmön
  • 322
  • 2
  • 14
0

That commandlet is called Set-AzureRMCurrentStorageAccount.

Alex Belotserkovskiy
  • 4,012
  • 1
  • 13
  • 10
  • 1
    So that command doesn't work. I see currentstorageaccount as blank when I execute Get-AzureRmSubscription | select * – Mitul Apr 22 '16 at 21:45
  • It sets on the context so if I do Get-AzureRMContext it give me the CurrentStorageAccount – Mitul Apr 22 '16 at 21:48
0

Exactly as you said, set-azureRmCurrentStorageAccount -context $Ctx will set your default Storage account to context. I also can't find any articles to get out explanation on this. I think you can try to use Azure CLI to set your default Azure storage account in environment variables.

Alex Chen-WX
  • 521
  • 2
  • 5