无法按名称在Azure CLI中筛选资源。

huangapple go评论54阅读模式
英文:

Can't filter resources by name in Azure CLI

问题

Here's the translation of the provided text without the code:

当我执行以下命令(如此建议这里):

az resource list --query "[?location=='swedencentral']"

我得到了一个资源组列表,如预期的那样。其中一个名为se-tyr-business,我在清单中清楚地看到了包含以下部分。

> {
"changedTime": "2023-02-21T04:41:33.593799+00:00",
...
"location": "swedencentral",
"name": "se-tyr-business",
...
"type": "Microsoft.Web/sites"
}, ...

所以我想如果我将location替换为name,那么语法应该根据该参数生成一个筛选列表。然而,执行:

az resource list --query "[?name=='se-tyr-business']"

产生一个空列表,表明没有匹配项。我不明白我漏掉了什么。我还尝试从其他来源中获取灵感,建议不使用括号中的条件,而是可以直接提取参数的值。

az resource list --query location --output table
az resource list --query name --output table

然而,这完全没有产生任何内容(没有虚拟对象,没有空数组,什么都没有,什么都没有,什么都没有)!所以我感到困惑(肯定是错误的),不知道该如何继续。关于列表的官方文档非常简短,我发现很难在博客中找到有信息的示例。此外,很多示例似乎针对Azure Powershell,而这不是我的兴趣所在。

英文:

When I execute the following command (as suggested here):

az resource list --query "[?location=='swedencentral']"

I get a list of resource groups, as expected. One of them is named se-tyr-business and I see it in the listing clearly containing the following section.

> {
"changedTime": "2023-02-21T04:41:33.593799+00:00",
...
"location": "swedencentral",
"name": "se-tyr-business",
...
"type": "Microsoft.Web/sites"
}, ...

So I figured that if I substitute location for name, then the syntax should produce a filtered list by that parameter. However, executing:

az resource list --query "[?name=='se-tyr-business']"

produces an empty list, suggesting that there's no matches. I don't understand what I'm missing. I also tried to get inspiration from other sources suggesting that instead of the condition in the brackets, I may simply pull out a parameter's values.

az resource list --query location --output table
az resource list --query name --output table

However, that produced no content at all (no dummy object, no empty array, nothing, nada, ziltch)! So I'm confused (and surely mistaken) as to how to continue. The official docs on listing is rahter brief and I find it hard to locate informative examples in blogs. Also, a lot of examples seem to target Azure Powershell, which isn't my interest.

答案1

得分: 1

我已在我的环境中重现,并获得了以下预期结果,按照Microsoft文档的步骤进行操作:

az resource list --query "[?location=='swedencentral']"

输出:

无法按名称在Azure CLI中筛选资源。

然后使用:

az resource list --query "[?name=='CRLB-IP']"

输出:

无法按名称在Azure CLI中筛选资源。

无法按名称在Azure CLI中筛选资源。

要获取特定位置的名称:

az resource list --query "[?location=='swedencentral'].{Name:name}"

输出:

无法按名称在Azure CLI中筛选资源。

az resource list --query "[?location=='swedencentral'].name"

输出:

无法按名称在Azure CLI中筛选资源。

您可以使用&&运算符来获取特定位置和名称:

az resource list --query "[?location=='swedencentral'] && [?name=='CRLB-IP']"

输出:

无法按名称在Azure CLI中筛选资源。

英文:

I have reproduced in my environment and got expected results as below and followed Microsoft-Document:

az resource list --query "[?location=='swedencentral']"

Output:

无法按名称在Azure CLI中筛选资源。

Then used:

 az resource list --query "[?name=='CRLB-IP']"

Output:

无法按名称在Azure CLI中筛选资源。

无法按名称在Azure CLI中筛选资源。

To get the names in particular Loaction:

az resource list --query "[?location=='swedencentral'].{Name:name}"

Output:

无法按名称在Azure CLI中筛选资源。

az resource list --query "[?location=='swedencentral'].name"

Output:

无法按名称在Azure CLI中筛选资源。

You can use && operator to get particular location and name:

az resource list --query "[?location=='swedencentral'] && [?name=='CRLB-IP']"

Output:

无法按名称在Azure CLI中筛选资源。

huangapple
  • 本文由 发表于 2023年5月6日 21:12:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189089.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定