If you have multiple Microsoft Azure subscriptions, it can be challenging to keep track of them all. So PowerShell to the rescue! With the use of Azure PowerShell commands installed Azure Cloud Shell, I'll show you how to view your subscriptions, and change to different subscriptions available to you. From there, you can build resources in Azure using the default subscription.
Want to follow along in Azure Cloud Shell? Create a free trial account here and then browse to shell.azure.com to begin.
First, let's list out all of the Azure subscriptions you have. This will provide you the names, subscription IDs and more. Both of these can be used for specifying your subscription
To view the number of subscriptions in your login, use Get-AzSubscription | measure.
Get-AzSubscription | measure
To list all of the subscriptions for your login & page through the list, use Get-AzSubscription | more. Notice you get the Name and Subscription ID that can be used
Get-AzSubscription | more
You can use copy and paste to select the Subscription ID or Subscription Name. Why do that when we can have PowerShell do the work for you. To views specific properties of a subscription, enter
Knowing the subscription name or Id will allow you to work with resources by explicitly calling out the subscription information. But sometimes, you want all of your actions in the shell to be against the same subscription. First, you need to verify what subscription you are using by entering get-AzureRMContext to view the default subscription name.
get-AzureRMContext
This will tell you what Azure subscription is the default subscription, and used with all commands when a Subscription isn't specified.
To change the subscription context for use with all processes in the current user session, enter the following command:
Now let's verify this works as it should by creating a resource group, and then viewing all the resource groups in the default description. To create a resource group in the default subscription, enter
To view all the resource groups in the default subscription, enter Get-AzureRmResourceGroup
Get-AzureRmResourceGroup
And that's it. All the commands you need to find your Azure subscriptions and start using them to build resources in your Azure subscription.