1 min read

Get subscription ID with Azure CLI

Use this Azure CLI command if you don't want to access the Azure portal every time you need a subscription ID.

az account show \
    --query id \
    --output tsv

Or, assign the subscription ID to a variable to use later in another CLI command.

SUBSCRIPTION_ID=$(az account show \
    --query id \
    --output tsv)
echo $SUBSCRIPTION_ID

For more details, click on the link below to access the official documentation

Get subscription and tenant IDs in the Azure portal - Azure portal
Learn how to locate and copy the IDs of Azure tenants and subscriptions.