如何通过az-rest方法进行查询



虽然我是JMESPath的新手,但即便如此,我还是感到特别惊讶,因为我提取的文档中没有一个可以轻松使用的相对工作示例。例如,从Query Azure CLI命令输出中,忽略了返回的输出如何包装在value密钥中——正如GitHub中的一个问题所解释的那样;但即使尝试这种语法,我也没有得到任何积极的结果。

我需要做的是返回类似以下内容的集合:

az rest --method get --url https://graph.microsoft.com/v1.0/directoryRoles/ --query "[?contains(displayName,'Administrator')]" --output json

预期回报应为:

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryRoles",
"value": [
{
"deletedDateTime": null,
"displayName": "Foo Administrator",
"id": "09fe6ef5-4af5-650d-a2e5-63895bba8f16",
"otherId": "4d2ac1ba-3253-41a0-a1f9-a3e0f568773a"
},
{
"deletedDateTime": null,
"displayName": "Bar Administrator",
"id": "1602300e-a17b-42d0-97a2-e3d0f0c1fa14",
"otherId": "fda7a751-a60a-444b-974d-02352ee8fa1c"
},
{
"deletedDateTime": null,
"displayName": "Foobar Service Administrator",
"id": "f94ad3a3-5e69-4638-b47d-e4df2d831dc8",
"otherId": "59091246-12e8-4a86-aa5a-066175b1a7a8"
},
[...]

。。。因此,根据Microsoft Graph文档,任何资源都不支持contains字符串运算符。但我能够通过jq:输出我的阵列

az rest --method get --url https://graph.microsoft.com/v1.0/directoryRoles/ 
| jq '.value[] | select(.displayName | contains("Administrator"))'

最新更新