az cli use subscription

Mastering Azure CLI: Using Subscription Commands

By Richard Hernandez
AD

The Azure Cloud Shell (Azure CLI) offers a powerful way to manage your Azure resources. One of its key features is the ability to manage Azure subscriptions, a crucial aspect for organizations with multiple Azure deployments. Let's dive into how you can efficiently use the Azure CLI to manage your subscriptions.

Before we start, ensure you've logged in to Azure CLI by running the command `az login`. This will grant you access to your Azure subscriptions.

Managing Azure Subscriptions

The Azure CLI provides several commands to manage your subscriptions. Let's explore some of the key operations.

AD
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
Types of subscription services - infographic
Types of subscription services - infographic
How to Create an Amazing Subscription Website in Less Than a Day
How to Create an Amazing Subscription Website in Less Than a Day

First, you can list all your subscriptions with the `az account list` command. This will display a list of your subscriptions with their IDs, names, and statuses.

Selecting a Subscription

To work with a specific subscription, you need to set it as the current context. Use the `az account set` command followed by the subscription name or ID. For example, `az account set --subscription "MySubscription"`.

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
IPTV Smarters Pro Subscription - Official IPTV in the US
IPTV Smarters Pro Subscription - Official IPTV in the US
Use subscription templates
Use subscription templates

You can also set the default subscription for your current session with the `-d` flag, like so: `az account set -d "MySubscription"`. This will automatically use "MySubscription" for subsequent commands until you change it.

Switching Between Subscriptions

Once you've set a default subscription, you can switch between subscriptions using the `az account list` command and then setting the desired subscription with `az account set`.

AD

For a more seamless switch, consider using an alias or exporting the subscription name or ID to your shell environment variable. This will allow you to quickly switch between subscriptions with just a simple command.

Marketing Flyer for Capcut Subscription
Marketing Flyer for Capcut Subscription
How to start your own subscription business?
How to start your own subscription business?
Stylish 3D Web Design with Subscription Feature
Stylish 3D Web Design with Subscription Feature
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
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

Handling Subscriptions in Azure CLI

Besides setting subscriptions, the Azure CLI offers commands to list, create, update, and delete subscriptions. Let's briefly explore these operations.

To create a new subscription, use the `az account subscription create` command. This will prompt you to fill in the required information. Similarly, you can update a subscription's details with `az account subscription update` and delete a subscription with `az account subscription delete`.

AD

Using Azure CLI with Multiple Subscriptions

When working with multiple subscriptions, it's crucial to understand how the Azure CLI manages them. By default, the Azure CLI uses the subscription specified in the Azure portal's context. You can view this with the `az account show` command.

Digital Subscription Hub
Digital Subscription Hub
a circle with many different colored wires and the word subscriptions written on it
a circle with many different colored wires and the word subscriptions written on it
subscribe,youtube
subscribe,youtube
Step-by-Step Guide to Reducing Subscription Costs
Step-by-Step Guide to Reducing Subscription Costs
Software Subscriptions Are Something We Need To Get Used To
Software Subscriptions Are Something We Need To Get Used To
How Substack Works: Newsletters & Subscriptions
How Substack Works: Newsletters & Subscriptions
an image of a website page with different colors and font
an image of a website page with different colors and font
an email message with the caption'your subription has been successfully corrected '
an email message with the caption'your subription has been successfully corrected '
Hidden Opportunities:Subscription Boxes That Reduce CAC And Churn
Hidden Opportunities:Subscription Boxes That Reduce CAC And Churn
subscriptions
subscriptions
Kindness and the Boom of Subscription Economy
Kindness and the Boom of Subscription Economy
Download Subscribe video blog illustration concept for free
Download Subscribe video blog illustration concept for free
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
How to find and cancel your unused subscriptions - Engadget
How to find and cancel your unused subscriptions - Engadget

If you want to use a different subscription, you must set it as the current context using the `az account set` command. This ensures that the commands you run will use the specified subscription.

In conclusion, the Azure CLI provides a robust set of commands for managing Azure subscriptions. By mastering these commands, you can streamline your workflow and increase your productivity. Happy coding!

AD
AD