LinuxCommandLibrary

az-account

Manage Azure subscriptions and account information

TLDR

List all subscriptions for the logged in account

$ az account list
copy

Set a subscription to be the currently active subscription
$ az account set [[-s|--subscription]] [subscription_id]
copy

List supported regions for the currently active subscription
$ az account list-locations
copy

Print an access token to be used with MS Graph API
$ az account get-access-token --resource-type [ms-graph]
copy

Print details of the currently active subscription in a specific format
$ az account show [[-o|--output]] [json|tsv|table|yaml]
copy

SYNOPSIS

az account <SUBCOMMAND> [OPTIONS]

Common Subcommands:
az account list [--all]
az account show [--subscription <SUBSCRIPTION_ID_OR_NAME>]
az account set --subscription <SUBSCRIPTION_ID_OR_NAME>
az account clear

PARAMETERS

--subscription <SUBSCRIPTION_ID_OR_NAME>
    Specifies the target Azure subscription by its ID or name for the operation. This parameter is commonly used with `az account show` or `az account set`.

--all
    Used with `az account list` to display all subscriptions associated with your account, including those that might be disabled or inactive.

--output <FORMAT>
    Specifies the output format for the command's results. Common formats include `json`, `jsonc` (colored JSON), `tsv` (tab-separated values), `table`, `yaml`, `yamlc`, or `none`.

--query <JMESPATH_QUERY>
    A JMESPath query string that allows you to filter or transform the command's JSON output, enabling extraction of specific data points.

--debug
    Increases logging verbosity to display all debug logs. This is useful for troubleshooting issues and understanding the underlying operations.

--help, -h
    Displays the command's help message, providing a brief description of its usage, subcommands, and available options, then exits.

DESCRIPTION

The `az account` command group within the Azure CLI is a fundamental tool for interacting with your Azure subscriptions and managing your account context.
It allows users to list available subscriptions, view details of the currently active subscription, and most importantly, set a specific subscription as the default for subsequent Azure CLI operations.
This functionality is crucial for users working in environments with multiple Azure subscriptions, ensuring that commands are executed against the intended subscription.
Beyond managing the active context, `az account` also provides commands to clear stored subscription information and retrieve access tokens for programmatic use.
It acts as the central point for navigating your identity and billing boundaries within Azure, providing a clear overview of your access permissions and the scope of your CLI commands.

CAVEATS

Authentication Required: Before using `az account` commands, you must authenticate to Azure using `az login`. The CLI needs valid credentials to retrieve and manage subscription information.
Permissions: Your Azure identity must possess the necessary permissions (e.g., Reader role on the subscription) to list, show, or modify subscription settings. Lack of permissions will result in errors.
Active Context: In multi-subscription environments, always verify the currently active subscription to ensure commands are executed in the desired context, preventing accidental operations on the wrong resources.

<B>SETTING THE DEFAULT SUBSCRIPTION</B>

After logging into Azure CLI, you might have access to multiple subscriptions. To avoid specifying the `--subscription` parameter for every command, you can set a default subscription. First, list your available subscriptions using `az account list`. Then, set your desired subscription using: `az account set --subscription "<Subscription Name or ID>"`.

<B>VIEWING CURRENT ACCOUNT DETAILS</B>

To quickly confirm which Azure subscription is currently active in your CLI session, along with its details like name, ID, and tenant ID, execute the command: `az account show`. This provides an immediate overview of your current operational context.

<B>CLEARING LOCAL SUBSCRIPTION CACHE</B>

If you encounter issues with stale subscription data or wish to remove all locally cached subscription information, you can use `az account clear`. This command effectively logs you out of all subscriptions managed by the CLI without affecting your Azure Active Directory login token.

HISTORY

The `az account` command group is a foundational component of the modern Azure CLI, which saw its significant evolution and re-architecture from the earlier cross-platform (Xplat-CLI) to the Python-based version, released around 2016.
From its inception, the ability to manage Azure subscriptions was identified as a critical user requirement, especially as cloud adoption grew and organizations began utilizing multiple subscriptions for different environments (e.g., dev, test, prod) or departments.
Therefore, `az account` has been a stable and continuously improved command, central to the CLI's functionality in providing a robust interface for subscription and tenant management.

SEE ALSO

az login(1), az group(1), az resource(1), az ad(1)

Copied to clipboard