azure cli use subscription

Azure CLI: Manage Subscriptions Efficiently

By Andrew Garcia
AD

The Azure CLI (Command Line Interface) is a powerful tool for managing Azure resources. It allows you to control your Azure environment directly from the command line, making it an essential tool for automation and efficient workflows. Understanding how to use Azure CLI for subscription management is a crucial aspect of leveraging its capabilities.

Before diving into subscription management, ensure you have installed Azure CLI and configured it with your Azure account. You can verify your configuration by running 'az login' in the terminal, which will prompt you for your Azure credentials.

Understanding Azure CLI Subscriptions

Azure subscriptions are the foundation for managing your Azure resources. They represent your organization's access to Azure services and resources. Understanding how to navigate and manage these subscriptions using Azure CLI is pivotal.

AD
Azure CLI Cheat Sheet — Resource Groups & VM Reference
Azure CLI Cheat Sheet — Resource Groups & VM Reference
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
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

To list all your subscriptions, simply run the command: 'az account list'. This command will display a table with the subscription ID, name, and state of each subscription you have access to.

Selecting an Active Subscription

The Azure CLI uses the concept of an active subscription. All subsequent commands operate within this active subscription context. You can set an active subscription using the 'az account set' command. For example, to set the active subscription to one with ID '00000000-0000-0000-0000-000000000000', use the command: 'az account set --subscription 00000000-0000-0000-0000-000000000000'.

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
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
Announcing IoT extension for Azure CLI 2.0 | Microsoft Community Hub
Announcing IoT extension for Azure CLI 2.0 | Microsoft Community Hub

You can also list all subscriptions and set the active one directly from the output. For instance, if you have a subscription 'MySubscription' with ID '00000000-0000-0000-0000-000000000000', you can set it as active with: 'az account set -n MySubscription'.

Switching Between Subscriptions

Sometimes, you might need to switch between subscriptions to manage resources in each. Azure CLI allows you to do this easily. To list all subscriptions again, but only in a format suitable for switching, use: 'az account list --query "[].{Name:name, ID:id}" -otable'. Then, to switch to a subscription, use the 'az account set' command with the subscription's ID or name, as demonstrated in the previous sections.

AD

Remember, after switching subscriptions, all subsequent Azure CLI commands will now operate within the newly set subscription context.

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
Azure Kubernetes Service (AKS) vs Google Kubernetes Engine (GKE)
Azure Kubernetes Service (AKS) vs Google Kubernetes Engine (GKE)
Azure Basics Explained Simply ☁️ | Microsoft Azure Cloud Services
Azure Basics Explained Simply ☁️ | Microsoft Azure Cloud Services
the azure cloud mindmap diagram
the azure cloud mindmap diagram
Enable your Azure subscription for Data Lake Store - Part One
Enable your Azure subscription for Data Lake Store - Part One
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

Managing Azure Subscriptions

Azure CLI allows you to perform various operations on your subscriptions, apart from merely listing and switching between them.

Let's explore some of these operations using the 'az account' commands.

AD

Creating a New Subscription

To create a new subscription, use the 'az account creating' command. This command requires several parameters, including the subscription name, location, and offer. For example: 'az account creating --name "NewSubscription" --location "eastus" --offer "MS-AZR-0003P".'

Azure Integration Services for Business Modernization
Azure Integration Services for Business Modernization
Microsoft Strategy Teardown
Microsoft Strategy Teardown
Create A Xamarin.Forms App Using Azure Mobile Services
Create A Xamarin.Forms App Using Azure Mobile Services
the azure cloud service sheet is shown in this graphic, it shows different types of services
the azure cloud service sheet is shown in this graphic, it shows different types of services
Extract Text From Images Using Computer Vision API and Azure Functions
Extract Text From Images Using Computer Vision API and Azure Functions
Igor Iric on LinkedIn: #azure #datamanagement #analytics #databricks #cloudarchitecture #cloud…
Igor Iric on LinkedIn: #azure #datamanagement #analytics #databricks #cloudarchitecture #cloud…
Choose an Azure Compute Service - Azure Architecture Center
Choose an Azure Compute Service - Azure Architecture Center
Knowledge 18062024
Knowledge 18062024
Explore Azure Documenter
Explore Azure Documenter
the azure logo on top of a blue cloud
the azure logo on top of a blue cloud

Additional parameters, like billing profile and plan, might be required depending on your Azure offer. You can find these details in the Azure portal or by running 'az account creating -h' for more options.

Deleting a Subscription

To delete a subscription, use the 'az account delete' command. You need to provide the ID or name of the subscription you want to delete. For example: 'az account delete --subscription MySubscriptionName' to delete a subscription named 'MySubscriptionName'.

AD

Note that deleting a subscription also deletes all the resources contained within it. Ensure you've exported or transferred any necessary resources before proceeding with this command.

With this understanding of managing Azure subscriptions using Azure CLI, you're ready to efficiently manage your Azure environment. Stay ahead of the curve by regularly updating your knowledge of the latest Azure CLI features and best practices.

AD