PowerTip: Set Default Storage Account for PowerShell Cmdlets in Azure


Summary: Learn how to define the default storage account to be used with the Azure PowerShell cmdlets.

Hey, Scripting Guy! Question How do I tell Azure which media or storage account I'd like to use when I create a virtual machine?

Hey, Scripting Guy! Answer Use Get-AzureStorageAccount to access the names of your storage accounts, and
           then use Set-AzureSubscription to define your current default for the cmdlets.

The following example sets the first account as the default in the subscription called 'HSG Azure Subscription':

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

Set-AzureSubscription –SubscriptionName 'HSG Azure Subscription'
–CurrentStorageAccountName $StorageAccount 


Comments (2)

  1. Praveen kumar potnuru says:

    while running the script it is throwing an error :

    Set-AzureSubscription : Cannot bind positional parameters because no names were given.
    At line:3 char:1
    + Set-AzureSubscription $subscriptionName -CurrentStorageAccount $storageaccount
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Set-AzureSubscription], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousPositionalParameterNoName,Microsoft.WindowsAzure.Commands.Profile.SetAzureSubscriptionCommand

    can you please help me to resolve the issue.

  2. Patrick says:

    I am trying to set the Storage account on a subscription to a storage account created with AzureRmStorageAccount

    #create Storage Account
    New-AzureRmStorageAccount -Location $location -Name $DestStorageAccount -ResourceGroupName $resourceGroupName -type “Standard_LRS” -Verbose
    $currentStorageAccount=(Get-AzureRmStorageAccount -Name aznssubscriptionstorage -ResourceGroupName aznssubscription-rg).StorageAccountName
    # Assign to the current subscription
    Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccountName $currentStorageAccount
    This results in an error, stating it cannot find the storage account….
    “Set-AzureSubscription : ResourceNotFound: The storage account ‘aznssubscriptionstorage’ was not found.”
    Any ideas of a work around for this discrepancy…

Skip to main content