Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list containing only Azure region names?

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",
}
like image 240
DenaliHardtail Avatar asked Jul 12 '18 18:07

DenaliHardtail


2 Answers

You can use -query parameter for that:

az account list-locations --query '[].name'

its using a jmespath notation.

ps. some examples.

like image 64
4c74356b41 Avatar answered Nov 02 '22 13:11

4c74356b41


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

like image 3
Curt Keisler Avatar answered Nov 02 '22 11:11

Curt Keisler