英文:
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']"
输出:
然后使用:
az resource list --query "[?name=='CRLB-IP']"
输出:
要获取特定位置的名称:
az resource list --query "[?location=='swedencentral'].{Name:name}"
输出:
az resource list --query "[?location=='swedencentral'].name"
输出:
您可以使用&&运算符来获取特定位置和名称:
az resource list --query "[?location=='swedencentral'] && [?name=='CRLB-IP']"
输出:
英文:
I have reproduced in my environment and got expected results as below and followed Microsoft-Document:
az resource list --query "[?location=='swedencentral']"
Output:
Then used:
az resource list --query "[?name=='CRLB-IP']"
Output:
To get the names in particular Loaction:
az resource list --query "[?location=='swedencentral'].{Name:name}"
Output:
az resource list --query "[?location=='swedencentral'].name"
Output:
You can use && operator to get particular location and name:
az resource list --query "[?location=='swedencentral'] && [?name=='CRLB-IP']"
Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论