Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default storage Account for Azure RM Subscription

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.

like image 495
Mitul Avatar asked Apr 22 '16 21:04

Mitul


People also ask

Which is set up by default when you create an Azure storage account?

Standard is selected by default, can be changed based upon your choice. Account kind, there are 5 types of account.

How do I change the default subscription for Azure PowerShell?

To change the azure subscription using PowerShell, we can use the Select-AZSubscription command. When you use this command, you can use either the subscription ID, Subscription Name, or the Tenant ID.

What is Azure RM account?

Description. The Connect-AzureRmAccount cmdlet connects to Azure with an authenticated account for use with Azure Resource Manager cmdlet requests. You can use this authenticated account only with Azure Resource Manager cmdlets.


2 Answers

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"
like image 81
NER1808 Avatar answered Oct 19 '22 04:10

NER1808


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
like image 2
Lemon Calamitous Avatar answered Oct 19 '22 04:10

Lemon Calamitous