In the Azure Cloud Shell, I can use az account list-locations
to get a list of all the locations supported in my subscription. How can I filter the response to only include the name property of the location and exclude all other properties?
Instead of a list of objects like this:
{
"displayName": "UK West",
"id": "<<removed>>",
"latitude": "53.427",
"longitude": "-3.084",
"name": "ukwest",
"subscriptionId": null
}
I want to get collection of names like this:
{
"name": "ukwest",
"name": "ukwest2",
"name": "ukwest3",
}
You can use -query
parameter for that:
az account list-locations --query '[].name'
its using a jmespath notation.
ps. some examples.
The accepted answer didn't work for me.
I'm using the az
CLI version 2.3.1.
This is what worked for me:
az account list-locations --query "sort_by([].{Location:name}, &Location)" -o table
Which yields this result:
Location
------------------
australiacentral
australiacentral2
australiaeast
australiasoutheast
brazilsouth
canadacentral
canadaeast
centralindia
centralus
eastasia
eastus
eastus2
francecentral
francesouth
germanynorth
germanywestcentral
japaneast
japanwest
koreacentral
koreasouth
northcentralus
northeurope
norwayeast
norwaywest
southafricanorth
southafricawest
southcentralus
southeastasia
southindia
switzerlandnorth
switzerlandwest
uaecentral
uaenorth
uksouth
ukwest
westcentralus
westeurope
westindia
westus
westus2
You can find more details on the query language here:
Query Azure CLI command output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With