April 12, 2020

How to Find your TenantId and subscriptionId in Azure

How to find your tenantId and subscriptionId from the CLI in Azure.

There are a number of ways to find this information, here I will highlight some handy ways to access your tenant and subscription id's from the CLI. This info is handy when using Terraform or another automation script to provision resources in an alternative subscriptionId.

You can run any of these commands from the Azure Cloud Shell or azure CLI. To access the Cloud Shell  from the web click the Cloud Shell icon.

Show default Account Info

To see all your default account info in a JSON formatted output use the following:

az account show

The output will look as follows:

{
  "environmentName": "AzureCloud",
  "homeTenantId": "ffffff-bbbbb-22222-333333-444444444",
  "id": "fffffff-ffffff-1111-2222-3333333", <---Your SubscriptionID
  "isDefault": true,
  "managedByTenants": [],
  "name": "PAYG",
  "state": "Enabled",
  "tenantId": "ffffff-bbbbb-22222-333333-444444444",<----- Your TenantID
  "user": {
    "cloudShellID": true,
    "name": "[email protected]",
    "type": "user"
  }
}

Show All Account info

To show all of the accounts you have access to under your account use the following command:

az account list

Output will be a formatted list with JSON formatted accounts as follows:

  {
    "cloudName": "AzureCloud",
    "homeTenantId": "ffffff-bbbbb-22222-333333-444444444",
    "id": "fffffff-ffffff-1111-2222-6666666", <----SubscriptionID
    "isDefault": false,
    "managedByTenants": [],
    "name": "BYOL",
    "state": "Enabled",
    "tenantId": "ffffff-bbbbb-22222-333333-444444444", <----tenantId
    "user": {
      "cloudShellID": true,
      "name": "[email protected]",
      "type": "user"
    }
  },
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "ffffff-bbbbb-22222-333333-444444444",
    "id": "fffffff-ffffff-1111-2222-3333333", <--- Subscription ID
    "isDefault": true,  <----Your default account
    "managedByTenants": [],
    "name": "PAYG",
    "state": "Enabled",
    "tenantId": "ffffff-bbbbb-22222-333333-444444444", <---Tenant ID
    "user": {
      "cloudShellID": true,
      "name": "[email protected]",
      "type": "user"
    }
  }
]

Subscription ID

To print out the SubscriptionId 's you have access to use the following command :

az account list -o table

The print out will look as follows:

PS /home/user> az account list --output table
Name         CloudName    SubscriptionId                        State    IsDefault
-----------  -----------  ------------------------------------  -------  -----------
BYOL  AzureCloud   fffffff-ffffff-1111-2222-6666666  Enabled  False
PAYG  AzureCloud   fffffff-ffffff-1111-2222-3333333  Enabled  True

TenantID

To print out the tenantID's you have access to use the following command

az account show -o table

The print out will look as follows:

PS /home/user> az account show --output table
EnvironmentName    HomeTenantId                          IsDefault    Name         State    TenantId
-----------------  ------------------------------------  -----------  -----------  -------  ------------------------------------
AzureCloud         ffffff-bbbbb-22222-333333-444444444         True      PAYG      Enabled       ffffff-bbbbb-22222-333333-444444444