我正在运行下面的azure cli命令来获取特定管理组的订阅ID。
命令:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r
输出:
{
"children": [
{
"children": null,
"displayName": "TestSub-ABC-Dev",
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": null,
"type": "/subscriptions"
},
{
"children": null,
"displayName": "TestSubIdentity",
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": null,
"type": "/subscriptions"
},
{
"children": null,
"displayName": "TestSub-Build-DevTest",
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": null,
"type": "/subscriptions"
},
{
"children": null,
"displayName": "Azure ITI - TestSub Pre-prod",
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": null,
"type": "/subscriptions"
},
{
"children": null,
"displayName": "TestSub-IS-Demo",
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": null,
"type": "/subscriptions"
},
{
"children": null,
"displayName": "TestSub-PQR-QA",
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": null,
"type": "/subscriptions"
},
{
"children": null,
"displayName": "TestSub-PQR-PreProd",
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": null,
"type": "/subscriptions"
}
],
"details": {
"parent": {
"displayName": "Simple-DMG-v01",
"id": "/providers/Microsoft.Management/managementGroups/Simple-DMG-v01",
"name": "Simple-DMG-v01"
},
"updatedBy": null,
"updatedTime": "0001-01-01T00:00:00",
"version": 0.0
},
"displayName": "Simple-NonProduction-EMG-v01",
"id": "/providers/Microsoft.Management/managementGroups/Simple-NonProduction-EMG-v01",
"name": "Simple-NonProduction-EMG-v01",
"roles": null,
"tenantId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"type": "/providers/Microsoft.Management/managementGroups"
}
我运行以下命令,但它没有给出无输出。
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query [].[children]
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query [].[children.children.name]
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query [].[children.children]
我不明白
无输出:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query 'children.children.name'
使用单引号的参考: https://docs.microsoft.com/en-us/cli/azure/query-azure-cli?view=azure-cli-latest
使用方括号的参考: https://adamraffe.com/azure/2017/11/22/the-wonderful-world-of-azure-cli-jmespath-queries/
非常感谢您的投入。
谢谢
答案 0 :(得分:1)
尝试通过这种方式进行操作:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query `children`
并这样:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query 'children[].name'