【问题标题】:How do I get a list containing only Azure region names?如何获取仅包含 Azure 区域名称的列表?
【发布时间】:2018-07-12 18:25:45
【问题描述】:

在 Azure Cloud Shell 中,我可以使用 az account list-locations 获取订阅中支持的所有位置的列表。如何过滤响应以仅包含位置的名称属性并排除所有其他属性?

而不是像这样的对象列表:

{
"displayName": "UK West",
"id": "<<removed>>",
"latitude": "53.427",
"longitude": "-3.084",
"name": "ukwest",
"subscriptionId": null
}

我想收集这样的名字:

{
"name": "ukwest",
"name": "ukwest2",
"name": "ukwest3",
}

【问题讨论】:

  • 从技术上讲,您的 JSON 无效,它不能包含重复的键。它应该是[] - 所以一个包含字符串或对象的数组

标签: azure azure-cloud-shell


【解决方案1】:

您可以为此使用-query 参数:

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

它使用jmespath 表示法。

ps。 some 例子。

【讨论】:

    【解决方案2】:

    接受的答案对我不起作用。

    我使用的是az CLI 2.3.1 版。

    这对我有用:

    az account list-locations --query "sort_by([].{Location:name}, &Location)" -o table
    

    产生这个结果:

    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
    

    您可以在此处找到有关查询语言的更多详细信息:

    Query Azure CLI command output

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      相关资源
      最近更新 更多