Search code examples
azureazure-cloud-shell

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",
}

Solution

  • You can use -query parameter for that:

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

    its using a jmespath notation.

    ps. some examples.