az cli specify subscription

"Azure CLI: How to Specify a Subscription"

By Richard Taylor
AD

In the ever-evolving landscape of cloud computing, managing and navigating through multiple Azure subscriptions can sometimes feel like a daunting task. But worry not, as Microsoft Azure provides a robust tool, the Azure CLI, to simplify this process. Today, we're going to delve into a key feature of the Azure CLI: how to specify a subscription.

Before we dive in, let'sremember why managing subscriptions is crucial. Azure allows you to create multiple subscriptions to organize your resources effectively, control access, and manage your costs. However, to perform operations on these subscriptions using the Azure CLI, you need to switch between them first. This is where 'az login' and 'az account set' commands come into play.

Logging into Azure CLI

Before you can interact with your Azure subscriptions, you need to log in to the Azure CLI. This process associates your local Azure CLI installation with your Azure account, giving you access to all your respective subscriptions.

AD
a cell phone with the subs section highlighted in black and white text on it
a cell phone with the subs section highlighted in black and white text on it
a blue and white poster with the words azure cli commands on it's side
a blue and white poster with the words azure cli commands on it's side
an email message with the caption'your subription has been successfully corrected '
an email message with the caption'your subription has been successfully corrected '

To log in, use the 'az login' command. This command opens a browser window where you enter your credentials. Post-login, the Azure CLI displays a confirmation, and you're ready to proceed.

Listing Available Subscriptions

Before you switch to a specific subscription, it's helpful to know the ones available to your logged-in account. Use the 'az account list' command to list all the subscriptions you have access to. This gives you a comprehensive overview, helping you select the right one for your intended operations.

Types of subscription services - infographic
Types of subscription services - infographic
Group Subscription Pricing Page 1
Group Subscription Pricing Page 1
Subscription & Account
Subscription & Account

Each listed subscription displays details like its name, ID, IsDefault, and State. The 'IsDefault' field signifies whether the subscription is your default subscription - the one that the Azure CLI uses by default for commands that don't specify a subscription.

Setting a Default Subscription

After you've listed your subscriptions, you might want to set a default subscription. This subscription will be your go-to for commands that don't specify a subscription. To set a default subscription, use the 'az account set' command followed by the ID or the name of your desired subscription.

AD

For instance, 'az account set --subscription "My Favorite Subscription"' changes your default subscription to 'My Favorite Subscription'.

Use subscription templates
Use subscription templates
Choose a subscription plan
Choose a subscription plan
the app is showing how to use subscription for an email message or email address
the app is showing how to use subscription for an email message or email address
Azure CLI Cheat Sheet — Resource Groups & VM Reference
Azure CLI Cheat Sheet — Resource Groups & VM Reference
How to Create an Amazing Subscription Website in Less Than a Day
How to Create an Amazing Subscription Website in Less Than a Day
Digital Subscription Hub
Digital Subscription Hub

Switching Between Subscriptions

Now that you understand how to list and set default subscriptions, let's dive into switching between subscriptions. Sometimes you might need to perform operations on a specific subscription that isn't your default. In such cases, use the 'az account set' command with the name or ID of the subscription you want to switch to.

Suppose you need to switch to a subscription named 'My Second Subscription'. You can achieve this by running 'az account set --subscription "My Second Subscription"'. Now, all subsequent commands that don't specify a subscription will operate on 'My Second Subscription'.

AD

Using the Subscription ID

Alternately, you can also use the subscription ID to switch subscriptions. Use the 'az account set' command followed by '--subscription-id' and the ID of your desired subscription.

Too many subscriptions and memberships.
Too many subscriptions and memberships.
an image of a website page with the words turn your shoppers into subscibers
an image of a website page with the words turn your shoppers into subscibers
the word subscribe in red on a black background
the word subscribe in red on a black background
a text message that reads, dear subber your one month subscription has been recharged successfully
a text message that reads, dear subber your one month subscription has been recharged successfully
Software Subscriptions Are Something We Need To Get Used To
Software Subscriptions Are Something We Need To Get Used To
Cancel or Keep? How to Cut Subscription Costs Without Losing What You Love | AAA Club Alliance
Cancel or Keep? How to Cut Subscription Costs Without Losing What You Love | AAA Club Alliance
Subscriptions
Subscriptions
Subscribe icon
Subscribe icon
Inbox Zero used to take daily discipline. Now AI does it. Unsubscribes dead lists, categorizes subscriptions, identifies what you actually open, learns your preferences over time. The more you use your email, the smarter it gets. 🧠 #ConnectedAI #AIHistory #InboxZero #EmailAI #Productivity #AIFor
Inbox Zero used to take daily discipline. Now AI does it. Unsubscribes dead lists, categorizes subscriptions, identifies what you actually open, learns your preferences over time. The more you use your email, the smarter it gets. 🧠 #ConnectedAI #AIHistory #InboxZero #EmailAI #Productivity #AIFor
an email message is being displayed on the iphone's homepage, with text added
an email message is being displayed on the iphone's homepage, with text added
TOP 5 BENEFITS OF A SUBSCRIPTION MODEL & HOW TO UTILIZE
TOP 5 BENEFITS OF A SUBSCRIPTION MODEL & HOW TO UTILIZE
subscribe,youtube
subscribe,youtube

Let's say your subscription 'My Second Subscription' has an ID of '/subscriptions/abc123def456'. You can switch to this subscription using 'az account set --subscription-id /subscriptions/abc123def456'.

Verifying the Current Subscription

To verify which subscription is your current one, use the 'az account show' command. This command returns the details of your current subscription, confirming that you're operating on the desired subscription.

AD

Remember, this command doesn't require any parameters. It simply returns the details of the subscription that the Azure CLI is currently operating on.

Now you're equipped with the knowledge to effortlessly switch between Azure subscriptions using the Azure CLI. With this, navigating through multiple subscriptions becomes a breeze, allowing you to manage your resources more effectively. Happy cloud computing!

AD