Skip to content

Instantly share code, notes, and snippets.

@codingoutloud
Created June 13, 2024 19:28
Show Gist options
  • Save codingoutloud/5d51bd2cefe11021173b7917655637db to your computer and use it in GitHub Desktop.
Save codingoutloud/5d51bd2cefe11021173b7917655637db to your computer and use it in GitHub Desktop.
Quickly see more salient properties of Azure Subscriptions for logged-in user. Use from Azure Shell or use "az login" as needed before running.
#!/bin/bash
# Bill Wilder, 13-June-2024
# Consider applying "chmod u+x az-sub-list.sh" or similar to a local copy of this file as you see fit.
# If not being invoked from Azure Shell you need to ensure you have authenticated via "az login" before running.
az account list --query '[].{Name:name, ID:id}' --output tsv | awk -F'\t' '{print "Azure Subscription ID \"" $2 "\" is for Subscription named \"" $1 "\""}'
USERNAME=$(az account show --query '{Name:user.name}' --output tsv)
DEFSUB=$(az account list --query '[?isDefault].{Name:name}' --output tsv)
echo ""
echo "You are logged in as $USERNAME with default subscription \"$DEFSUB\""
echo ""
echo "To change your default subscription, use the following command:"
echo " az account set --subscription <Subscription ID>"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment