How to manage Azure subscriptions – Azure CLI (2024)

  • Article

The Azure CLI helps you manage your Azure subscription, create management groups, and lock subscriptions.You might have multiple subscriptions within Azure. You can be part of more than one organization or your organization might divide access to certain resources across groupings. The Azure CLI supports selecting a subscription both globally and per command.

For detailed information on subscriptions, billing, and cost management, see the billing and cost management documentation.

Terminology

A tenant is an instance of Microsoft Entra ID in which information about a single organization resides. A multi-tenant organization is an organization that has more than one instance of Microsoft Entra ID. A tenant has one or more subscriptions and users.

Users are those accounts that sign in to Azure to create, manage, and use resources. A user may have access to multiple tenants and subscriptions.

Subscriptions are the agreements with Microsoft to use cloud services, including Azure. Every resource is associated with a subscription. Subscriptions contain resource groups.

An Azure resource group is a container that holds related resources for an Azure solution. To learn how to manage resource groups within your subscription, see How to manage Azure resource groups with the Azure CLI

Get the active tenant

Use az account tenant list or az account show to get the active tenant ID.

az account tenant listaz account show

Change the active tenant

To switch tenants, you have two options.

  • Change the active subscription.

  • Sign in as a user within the desired tenant. Use az login to change the active tenant and update the subscription list to which you belong.

    # sign in as a different useraz login --user <myAlias@myCompany.com> --password <myPassword># sign in with a different tenantaz login --tenant <myTenantID>

    If your organization requires multi-factor authentication, you may receive this error when using az login --user:

    Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access...

    Using the alternative az login --tenant command prompts you to open an HTTPS page and enter the code provided. You can then use multi-factor authentication and successfully sign in. To learn more about sign in options with the azure CLI, see Sign in with the Azure CLI.

Get subscription information

Most Azure CLI commands act within a subscription. You can specify which subscription to work in by using the --subscription parameter in your command. If you don't specify a subscription, the command uses your current, active subscription.

To see the subscription you're currently using or to get a list of available subscriptions, run the az account show or az account list command. Go to Learn to use Bash with the Azure CLI to see more examples of ways to use these commands.

Here are examples showing how to get subscription information:

# get the current default subscription using showaz account show --output table# get the current default subscription using listaz account list --query "[?isDefault]"# get a subscription that contains search words or phrasesaz account list --query "[?contains(name,'search phrase')].{SubscriptionName:name, SubscriptionID:id, TenantID:tenantId}" --output table

You can also store subscription information in a variable for use within a script.

  • Bash
  • PowerShell
# store the default subscription in a variablesubscriptionId="$(az account list --query "[?isDefault].id" --output tsv)"echo $subscriptionId# store a subscription of certain name in a variablesubscriptionId="$(az account list --query "[?name=='my case sensitive subscription full name'].id" --output tsv)"echo $subscriptionId

Tip

The --output parameter is a global parameter, available for all commands. The table value presents output in a friendly format. For more information, see Output formats for Azure CLI commands.

Change the active subscription

Azure subscriptions have both a name and an ID. You can switch to a different subscription using az account set specifying the desired subscription ID or name.

# change the active subscription using the subscription nameaz account set --subscription "My Demos"# change the active subscription using the subscription IDaz account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

You can also change your subscription using a variable. Here is an example:

  • Bash
  • PowerShell
# change the active subscription using a variablesubscriptionId="$(az account list --query "[?name=='my case sensitive subscription full name'].id" --output tsv)"az account set --subscription $subscriptionId

If you change to a subscription that is in a different tenant, you will also be changing the active tenant. To learn how to add a new subscription to your Microsoft Entra tenant, see Associate or add an Azure subscription to your Microsoft Entra tenant.

If you received a "The subscription of ... doesn't exist..." error, see Troubleshooting for possible solutions.

Clear your subscription cache

To update your subscription list, use the az account clear command. You will need to sign in again to see an updated list.

az account clearaz login

Clearing your subscription cache is not technically the same process as logging out of Azure. However, when you clear your subscription cache, you cannot run Azure CLI commands, including az account set, until you sign in again.

Create Azure management groups

Azure management groups contain subscriptions. Management groups provide a way to manage access, policies, and compliance for those subscriptions. For more information, see What are Azure management groups.

Use the az account management-group commands to create and manage Azure Management Groups.

You can create a management group for several of your subscriptions by using the az account management-group create command:

az account management-group create --name Contoso01

To see all your management groups, use the az account management-group list command:

az account management-group list

Add subscriptions to your new group by using the az account management-group subscription add command:

az account management-group subscription add --name Contoso01 --subscription "My Demos"az account management-group subscription add --name Contoso01 --subscription "My Second Demos"

To remove a subscription, use the az account management-group subscription remove command:

az account management-group subscription remove --name Contoso01 --subscription "My Demos"

To remove a management group, run the az account management-group delete command:

az account management-group delete --name Contoso01

Removing a subscription or deleting a management group doesn't delete or deactivate a subscription.

Set an Azure subscription lock

As an administrator, you may need to lock a subscription to prevent users from deleting or modifying it. For more information, see Lock resources to prevent unexpected changes.

In Azure CLI, use the az account lock commands. For instance, the az account lock create command can prevent users from deleting a subscription:

az account lock create --name "Cannot delete subscription" --lock-type CanNotDelete

Note

You need to have contributor permissions on a subscription to create or change locks.

To see the current locks on your subscription, use the az account lock list command:

az account lock list --output table

If you make an account read-only, the result resembles assigning permissions of the Reader role to all users. To learn about setting permissions for individual users and roles, see Add or remove Azure role assignments using Azure CLI.

To see details for a lock, use the az account lock show command:

az account lock show --name "Cannot delete subscription"

You can remove a lock by using the az account lock delete command:

az account lock delete --name "Cannot delete subscription"

Troubleshooting

The subscription doesn't exist

In addition to a typographical error, you can receive this error when there is a permissions timing issue. For example, if you have been given permissions to a new subscriptions while your current terminal window is open, this error can occur. The solution is to either close and reopen your terminal window, or use az logout then az login to refresh your available subscriptions list.

Here is a script to help you find and change a subscription.

# See what subscription you are currently using.az account show# Get a list of available subscriptions.az account list --output table# If the subscription you are seeking is not in the list# close and reopen your terminal window,# or logout and then sign in again.az logoutaz login# You can also clear your cache to refresh the# available subscription listaz account clearaz login# Did your available subscription list change?az account list --output table# If the subscription you are seeking is still not in the list,# contact your system administrator. You cannot change your# subscription to an ID that is not in the list.# If the subscription you are seeking is now in the list,# change your subscription.az account set --subscription 00000000-0000-0000-0000-00000000000

See also

  • Associate or add an Azure subscription to your Microsoft Entra tenant
  • Manage Azure resource groups
How to manage Azure subscriptions – Azure CLI (2024)

FAQs

How do I get a list of Azure subscriptions in CLI? ›

To list all subscriptions with Sub name, Sub ID, Status, Tags, and Parent Management Group using Azure CLI, you can use the following query: az graph query -q "Resources | where type == 'microsoft. resources/subscriptions' | extend managementGroup = tostring(properties.

How to change Azure subscription in CLI? ›

Change the active tenant
  1. Change the active subscription.
  2. Sign in as a user within the desired tenant. Use az login to change the active tenant and update the subscription list to which you belong. Azure CLI Copy. Open Cloud Shell.
Aug 27, 2024

How to manage subscriptions in Azure? ›

Sign in to the Azure portal. Select All services > Management groups. Select the management group that you want to be the parent. At the top of the page, select Add subscription.

Which CLI command can be used to select an Azure subscription? ›

Azure CLI vs Azure PowerShell: Side-by-side Command Comparison
CommandAzure CLIAzure PowerShell
Get available subscriptionsaz account listGet-AzSubscription
Set Subscriptionaz account set –-subscription <SubscriptionId>Set-AzContext -Subscription <SubscriptionID>
List Azure Locationsaz account list-locationsGet-AzLocation
1 more row
Jun 19, 2023

How do I see all my Azure subscriptions? ›

In the Azure portal, navigate to Subscriptions. In the top left area of the page, select the filter option. Select the link labeled global subscriptions filter. On the Portal settings | Directory + subscriptions page, under Default subscription filter, select the Select all option or select a subset of subscriptions.

How do I get subscription tags in AZ CLI? ›

To get the tags for a resource, resource group, or subscription, use the az tag list command and pass the resource ID of the entity.

How do I log into a particular subscription in Azure CLI? ›

Login through your browser with the az login command. Interactive login also gives you a subscription selector to automatically set your default subscription. Managed identities provide an Azure-managed identity for applications to use when connecting to resources that support Microsoft Entra authentication.

How do I switch to a different subscription in Azure? ›

Switch from a pay-as-you-go subscription
  1. Sign in to the Azure portal.
  2. Navigate to Subscriptions and then select your pay-as-you-go subscription.
  3. At the top of the page, select Switch Offer. ...
  4. Select the offer that you want from the list of offers your subscription can be switched to.
Feb 13, 2024

What is the Azure CLI command to list all team members? ›

You can list the individual members of a team in your organization with the az devops team list-member command. To get started, see Get started with Azure DevOps CLI.

How can I manage my subscriptions? ›

Manage your subscriptions on Google Play
  1. On your Android device, go to subscriptions on Google Play.
  2. Select the subscription you want to pause.
  3. Tap Manage. Pause payments.
  4. Set the time period to pause payments.
  5. Tap Confirm.

How do I change the current subscription in Azure PowerShell? ›

Change the active subscription

In order to change subscriptions, you use the Set-AzContext cmdlet to change the current context. You can use the Get-AzSubscription cmdlet to retrieve a list of your Azure subscriptions.

How do I assign access to Azure subscription? ›

At the Azure portal, select Subscriptions. Select the subscription you want to assign and then select Access Control. Select Add to add a user to the subscription. After you add the user to the subscription, you can assign the user a role and the account to which the user will have access.

What are Azure CLI commands? ›

The Azure command-line interface (Azure CLI) is a set of commands used to create and manage Azure resources. The Azure CLI is available across Azure services and is designed to get you working quickly with Azure, with an emphasis on automation.

What is Azure subscription directory? ›

Azure AD: Your directory for authentication and authorization. Azure Subscription: The container where your created resources are created. Billing is per subscription. (multiple subscription can have the same Azure AD). You can also set specific Azure policies on subscription level.

What are the main types of Azure subscriptions? ›

There are three main types of Azure subscriptions: Free, Pay-As-You-Go, and Enterprise Agreement. The Free subscription is ideal for individuals and small businesses to explore and experiment with Azure services. The Pay-As-You-Go subscription offers flexibility and scalability on a pay-as-you-use basis.

How do I export subscriptions from Azure? ›

To create or view a data export or to schedule an export, choose a scope in the Azure portal and select Cost analysis in the menu. For example, navigate to Subscriptions, select a subscription from the list, and then select Cost analysis in the menu.

How to list resource groups in Azure CLI? ›

To list the resource groups in your subscription, use az group list. To get one resource group, use az group show.

How many subscriptions are there in Azure? ›

There are three main types of Azure subscriptions: Free, Pay-As-You-Go, and Enterprise Agreement. The Free subscription is ideal for individuals and small businesses to explore and experiment with Azure services. The Pay-As-You-Go subscription offers flexibility and scalability on a pay-as-you-use basis.

References

Top Articles
Kawasaki Z1 KZ900 KZ 900 MKII KZ1000 H2 750 Z1R 1973 1974 MOTORCYCLES - wanted - by dealer - sale - craigslist
Top Dollar Paying Local Collector of Old Motorcycles CASH - wanted - by dealer - sale - craigslist
Bannerlord Campaign Or Sandbox
Stockmans Meat Company
895 Area Code Time Zone
Aflac on LinkedIn: Aflac Supplemental Insurance | 22 comments
Pbr Oklahoma Baseball
Saydel Botanica
U-Bolts - Screws, Bolts variety of type & configurable | MISUMI Thailand
Post-Tribune Obits
24-Hour Autozone On Hickory Hill
Sand Castle Parents Guide
Pokemon Fire Red Download Pc
Chittenden County Family Court Schedule
Splunk Append Search
Auto-Mataru
Where Is Gobblestone Castle
Does Publix Have Sephora Gift Cards
Seanna: meaning, origin, and significance explained
2013 Freightliner Cascadia Fuse Box Diagram
Only Murders In The Building Wiki
Osrs Toby
10 018 Sqft To Acres
Magicseaweed Bob Hall
Nbc Breaking News Nyc
Ethos West Mifflin
Courtney Callaway Matthew Boynton
Craigs List Waco
18443168434
France 2 Journal Télévisé 20H
Februarycash2023
Seriennummern aus dem Internet
Www Spherionnetwork.com
Ticket To Paradise Showtimes Near Laemmle Newhall
Dumb Money Showtimes Near Cinemark Century Mountain View 16
iPhone reconditionné
Did You Hear About Worksheet Answers Page 211
Skip The Games Albany
Jcp Meevo Com
Barbarian Frenzy Build with the Horde of the Ninety Savages set (Patch 2.7.7 / Season 32)
NO CLUE: deutsche Übersetzung von NCT 127
Snapcamms
158 Rosemont Ringoes Rd, East Amwell Twp, NJ, 08559 | MLS #3921765 | RocketHomes
Cetaphil Samples For Providers
Amariah Morales Snapchat
Botw Royal Guard
Wrdu Contests
Varsity Competition Results 2022
Restaurant Supply Store Ogden Utah
Democrat And Chronicle Obituaries For This Week
Kernersville pastor arrested after police find weapons, body armor and fentanyl in his Las Vegas Hotel room
Craigslist For Puppies For Sale
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated:

Views: 5896

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.