Azure: Setup CLI and get subscription information

Azure: Setup CLI and get subscription information

These are my notes on how to install Azure CLI 2.0, and do some basic setup.

Install azure-cli

This will install azure-cli on MacOsX

1
brew update && brew install azure-cli && brew install jq

Login and authenticate

  • Login to access acconts
1
az login
  • List all accounts
1
az account list
  • or in table informat
1
az account list -o table
  • List all accounts and filter for attribute “name” which will show you subscription name and emails
1
az account show | grep "name"

Setup default subscription

  • Switch to subscription
1
az account set -s "YOUR-CUSTOM-SUBSCRIPTION-NAME"
  • After you subscription is set, show the current subscription
1
az account show
  • Show detailed information on subscription
1
az account show -s "YOUR-CUSTOM-SUBSCRIPTION-NAME"

Filtering cheatsheet

  • Show only tenantId
1
az account show -o json | jq ".tenantId"
  • Show ony subscription id
1
az account show -o json | jq ".id"
  • Show both tenantId and subscription id
1
az account show -o json | jq ".tenantId, .id"