Use az cli to Query Multiple Fields of Resource Information
Use az cli to query multiple fields of VM information.
Here we need to use JMESPath language to implement it.
Typically, we will use az vm show to get the detailed VM
information:
1 | $ az vm show -g Linux -n alpha -d -o table |
However, this table doesn't contains the VM size. If we remove the
-o table argument, the VM size will be shown like this:
1 | $ az vm show -g Linux -n alpha -d |
Then we can get VM information with queries:
1 | $ az vm show -g Linux -n alpha -d --query 'hardwareProfile.vmSize' |
Can we get the powerState and the vmSize at the same time?
az vm show -g Linux -n alpha -d --query 'hardwareProfile.vmSize' --query 'powerState'
doesn't work. So how to query multiple fields of the json?
The answer is using JMESPath language, putting
all the required fields in the []:
1 | $ az vm show -g Linux -n alpha -d --query '[name, resourceGroup, powerState, hardwareProfile.vmSize]' -o tsv |
References: