azure cli subscription

Master Azure CLI: Manage Subscriptions with Ease

By Brian Moore
AD

The Azure CLI (Command Line Interface) is a powerful, cross-platform tool that enables you to manage Azure resources directly from your terminal. One of the key aspects of Azure management is understanding and navigating subscriptions, which is the focus of this guide. In this article, we will delve into a comprehensive exploration of using the Azure CLI to interact with subscriptions, ensuring you master essential tasks and unlock Azure's full potential.

Whether you're a seasoned Azure pro or just starting your cloud journey, this guide will provide you with a solid foundation on how to manage Azure subscriptions using the Azure CLI. So, let's dive right in and explore the key aspects of this crucial topic.

Understanding Azure Subscriptions

Before we dive into managing Azure subscriptions with the Azure CLI, let's briefly understand what subscriptions are. In Azure, a subscription represents a logical grouping of Azure resources. It defines the // where the resources are billed and is linked to a unique Azure Active Directory (Azure AD) tenant. Understanding subscriptions is fundamental to effective resource management.

AD
Azure CLI Cheat Sheet — Resource Groups & VM Reference
Azure CLI Cheat Sheet — Resource Groups & VM Reference
a family tree is shown with several different types of items in the same area, including two
a family tree is shown with several different types of items in the same area, including two
an image of a computer screen with the word azure in blue and green on it
an image of a computer screen with the word azure in blue and green on it

Now that we have a clear understanding of Azure subscriptions let's move on to managing them using the Azure CLI.

Listing Azure Subscriptions

The first step in managing Azure subscriptions is being aware of the subscriptions available to you. The Azure CLI provides a simple command to list all the subscriptions associated with your Azure account: az account list. This command displays a table with details about each subscription, including subscription ID, name, state, and additional information.

GitHub - Azure-Samples/azure-cli-samples: Contains Azure CLI scripts samples used for documentation at https://docs.microsoft.com
GitHub - Azure-Samples/azure-cli-samples: Contains Azure CLI scripts samples used for documentation at https://docs.microsoft.com
Upsell a subscription
Upsell a subscription
Azure for Beginners: Get a Free Subscription for Learning
Azure for Beginners: Get a Free Subscription for Learning

To make the output more readable, you can format it as JSON using --output table. Here's an example: az account list --output table.

Selecting an Azure Subscription

Once you've listed your subscriptions, you might want to select a specific subscription for commands that require a subscription context. You can do this using the az account set command, followed by the subscription ID or name. For instance, az account set --subscription "My Subscription Name" or az account set --subscription 00000000-0000-0000-0000-000000000000.

AD

To verify that you've successfully switched to the desired subscription, run az account show. It will display the subscription currently in use.

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
How to export cost reports from Azure subscription using the Azure Cost Management CLI
How to export cost reports from Azure subscription using the Azure Cost Management CLI
Enable your Azure subscription for Data Lake Store - Part One
Enable your Azure subscription for Data Lake Store - Part One
Azure Basics Explained Simply ☁️ | Microsoft Azure Cloud Services
Azure Basics Explained Simply ☁️ | Microsoft Azure Cloud Services
Azure Integration Services for Business Modernization
Azure Integration Services for Business Modernization
the azure logo on a blue background with white letters and an arrow in the middle
the azure logo on a blue background with white letters and an arrow in the middle

Managing Azure Subscriptions

Now that we've covered the basics of listing and selecting subscriptions, let's explore more advanced management tasks, such as creating, updating, and deleting subscriptions.

Creating an Azure Subscription

To create a new subscription, you'll firstly need to ensure you have the appropriate permissions in your Azure AD tenant. Once you've verified this, use the az account create command. You'll be prompted to provide subscription details such as name, location, and additional parameters. After creation, the Azure CLI will display the new subscription's ID and other details.

AD

Here's an example command to create a subscription: az account create --name "MyNewSubscription" --location "West Europe".

Azure Kubernetes Service (AKS) vs Google Kubernetes Engine (GKE)
Azure Kubernetes Service (AKS) vs Google Kubernetes Engine (GKE)
a blue cloud floating in the middle of a dark sky with bright lights around it
a blue cloud floating in the middle of a dark sky with bright lights around it
Announcing IoT extension for Azure CLI 2.0 | Microsoft Community Hub
Announcing IoT extension for Azure CLI 2.0 | Microsoft Community Hub
Expert Azure Consulting That Delivers Scalable and Secure Solutions
Expert Azure Consulting That Delivers Scalable and Secure Solutions
a poster with some notes on it that say azure clustering and how to use them
a poster with some notes on it that say azure clustering and how to use them
a blue cloud with the word azure on it
a blue cloud with the word azure on it
a man standing in front of a cloud with icons surrounding it and the word azure
a man standing in front of a cloud with icons surrounding it and the word azure
the azure logo on top of a blue cloud
the azure logo on top of a blue cloud
Knowledge 18062024
Knowledge 18062024
three men sitting at a table looking at a laptop computer with the words new from the azure blog
three men sitting at a table looking at a laptop computer with the words new from the azure blog
Microsoft's Azure is the best managed AI cloud service on the market
Microsoft's Azure is the best managed AI cloud service on the market

Updating an Azure Subscription

To update an Azure subscription, you can use the az account update command. This command allows you to modify the subscription's detail, such as the subscription name or location. For instance, to update the location of the subscription with ID 00000000-0000-0000-0000-000000000000, run az account update --subscription 00000000-0000-0000-0000-000000000000 --location "East US".

Deleting an Azure Subscription

Before deleting a subscription, ensure that you no longer need any of its resources, as deleting a subscription also removes all its underlying resources. To delete a subscription, use the az account delete command, followed by the subscription ID. For instance, az account delete --subscription 00000000-0000-0000-0000-000000000000.

AD

The Azure CLI will confirm the deletion, and all resources within the subscription will be removed.

In your Azure journey, mastering subscription management is a necessary skill. By understanding and proficiency in using the Azure CLI to manage subscriptions, you'll streamline your Azure resource management and unlock more efficient workflows.

AD