Target Azure Subscription with CLI: A Comprehensive Guide
The Azure CLI (Command Line Interface) is a powerful tool for managing Azure resources. One common task when working with Azure is specifying a particular subscription. This is crucial when your account has access to multiple subscriptions. Here's how you can use Azure CLI to work with specific subscriptions.
Before we dive into the details, ensure you've installed the Azure CLI and logged in with your credentials. You can check if you're logged in by running `az account show` which will display your current account details.
Switching Between Subscriptions
By default, Azure CLI uses the 'current' subscription. If you have access to multiple subscriptions, you need to switch to the desired one.
To list all your subscriptions, you can use:
``` az account list ```-switching to a subscription
Once you've identified the subscription you want to use, switch to it using:
Replace `
Setting a default subscription
If there's a specific subscription you use most frequently, you can set it as the default to avoid switching every time.
``` az account set --subscriptionWorking with Specific Subscriptions
Now that you're in the desired subscription, you can perform various operations. Let's look at some examples.
To list all the resources in a subscription, use:
``` az resource list ```Creating a resource in a specific subscription
When creating a resource, you can specify the subscription using the `
Upgrading a subscription
To upgrade a subscription, you can use:
``` az account upgrade --subscriptionThis can upgrade your subscription to a different pricing tier or upgrade to a new offer.
That's it! You've now learned how to use Azure CLI to work with specific subscriptions. Happy automating!