For system, network and cloud administrators

How to retrieve the admin username of your Azure virtual machine using Azure CLI

If you need to know what’s the admin username of a particular Azure virtual machine, use:

az vm show --resource-group YourResourceGroup --name YourVMName --query "osProfile.adminUsername"

How to list all Azure SKUs that contain a pattern using Azure CLI?

In order to view all SKUs that contain Standard_D2s in their name, for example, type:

az vm list-skus -o table --query "[?contains(name,'Standard_D2s')].name"


How to view an Azure resource group’s location using Azure CLI

In order to view a particular Azure resource group’s location, type in your shell:

az group show --resource-group yourresourcegroup --query location

How to delete all Azure storage accounts that start with a pattern using Azure CLI and Bash shell

In order to delete all Azure storage accounts that start with mystorage, for example, you’ll first need to run a Bash shell instead of PowerShell. Then, type:

az storage account list --query "[?starts_with(name,'mystorage')].[name]" --output tsv | xargs -L1 bash -c 'az storage account delete --name $0 --yes'


How to list all Azure storage accounts that start with a pattern using Azure CLI

In order to view a particular list of storage accounts that start with mystorage, for example, type:

az storage account list --query "[?starts_with(name,'mystorage')]".name --output tsv

The tsv output parameter can easily be replaced with table.