az account set subscription cli

Set Azure Subscription with CLI

By Joseph Martinez
AD

Managing Azure resources has never been simpler, thanks to the Azure CLI (Command Line Interface). One of the many tasks you can automate is managing Azure accounts, including subscriptions. Let's delve into how to set and manage subscriptions using the Azure CLI.

Before we start, ensure you have the Azure CLI installed on your machine. If not, you can download and install it from the official Microsoft website. Now, let's explore the world of Azure subscriptions through the CLI.

Setting Up Your Azure Account for CLI

Before you can manage subscriptions, you need to log in to your Azure account through the CLI. You can do this using the `az login` command. This command opens a browser session where you can authenticate your account.

AD
Subscription & Account
Subscription & Account
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
an iphone screen showing the account settings
an iphone screen showing the account settings

If you have multiple subscriptions, Azure CLI will set your default subscription. To verify this, use the `az account show` command. If you want to change your default subscription, you can do so using `az account set --subscription `.

List Your Subscriptions

Once logged in, you can list all your subscriptions using the `az account list` command. This command provides a JSON output listing all your subscriptions with their IDs and names.

Subscriber
Subscriber
the printable subcription tracker is shown on top of a white sheet with black writing
the printable subcription tracker is shown on top of a white sheet with black writing
Choose a subscription plan
Choose a subscription plan

If you prefer a tabular format, use the `az account list --table` command. It displays the same information but in a neat, readable table.

Selecting a Subscription

Azure CLI allows you to select a specific subscription to use for commands. You can list your subscriptions with the `az account list` command, note down the subscription ID, and then set it with `az account set --subscription `.

AD

To verify that you're using the correct subscription, use the `az account show` command. It displays the account details, including the currently selected subscription.

Digital Subscription Hub
Digital Subscription Hub
Millions In Bank Account, 1million Bank Account, Millionaire Bank Account, High Bank Account Balance, Millionaires Bank Account, Rich Bank Account, Rich Bank Account Aesthetic, Bank Account Screenshots, Bank Account With High Balance
Millions In Bank Account, 1million Bank Account, Millionaire Bank Account, High Bank Account Balance, Millionaires Bank Account, Rich Bank Account, Rich Bank Account Aesthetic, Bank Account Screenshots, Bank Account With High Balance
an email message with the caption'your subription has been successfully corrected '
an email message with the caption'your subription has been successfully corrected '
the word subscribe in red on a black background
the word subscribe in red on a black background
Subscriptions
Subscriptions
Types of subscription services - infographic
Types of subscription services - infographic

Managing Subscriptions

Now that we've covered how to list and select subscriptions, let's look at how to manage them, including creating and deleting subscriptions.

The Azure CLI doesn't directly support creating or deleting subscriptions. However, you can do this via the Azure portal or using Azure PowerShell. For predictable automation, consider using Azure Policy to manage subscriptions.

AD

Viewing Subscription Details

You can view the details of a specific subscription using the `az account show --subscription ` command. This provides details like the subscription ID, display name, and state.

an iphone screen showing the account details
an iphone screen showing the account details
an iphone screen showing the settings for different types of devices and numbers on it, including buttons
an iphone screen showing the settings for different types of devices and numbers on it, including buttons
a screen shot of the purchase form for a subshortion website, which is also available on amazon
a screen shot of the purchase form for a subshortion website, which is also available on amazon
hhc
hhc
the package successfully subscibed screen is shown
the package successfully subscibed screen is shown
the sign up screen for an email account
the sign up screen for an email account
the word subscibe is written in black on a white background
the word subscibe is written in black on a white background
a green and white subscibe button with the word subscibe on it
a green and white subscibe button with the word subscibe on it
the pricing page for an app that allows customers to purchase games and other items from their store
the pricing page for an app that allows customers to purchase games and other items from their store
a printable subscription tracker is shown in the middle of a colorful background
a printable subscription tracker is shown in the middle of a colorful background
Mastering the psychology of tiered pricing. Use anchors and clear value differentials to guide your customers toward your most profitable subscription tiers. #PricingStrategy #RevenueGrowth #EcommerceTips #BusinessStrategy Revenue Growth, Psychology, Business Strategy
Mastering the psychology of tiered pricing. Use anchors and clear value differentials to guide your customers toward your most profitable subscription tiers. #PricingStrategy #RevenueGrowth #EcommerceTips #BusinessStrategy Revenue Growth, Psychology, Business Strategy
How do I cancel my subscription?
How do I cancel my subscription?
$241 a month on subscriptions and I forgot about half of them
$241 a month on subscriptions and I forgot about half of them

The `az account list --filter` command lets you filter subscriptions based on certain criteria, like display name or state.

Moving Resources Between Subscriptions

If you want to move resources from one subscription to another, you can do so using the `az resource convert` command. Here's an example: `az resource convert --id --destination --destination-subscription `.

AD

Remember, you must have the appropriate permissions in both the source and destination subscriptions to move resources.

That's it! You now know how to set up and manage Azure subscriptions using the Azure CLI. This knowledge can greatly simplify your Azure resource management tasks. Happy coding!

AD