Reputation: 2840
I am running the below azure cli command to get the subscription ids for a particular management group.
Command:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r
Output:
{
"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"
}
I run the below commands but it gives no output.
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]
I do not understand
No output for the below command as well:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query 'children.children.name'
Reference to use single quotes: https://learn.microsoft.com/en-us/cli/azure/query-azure-cli?view=azure-cli-latest
Reference to use square brackets: https://adamraffe.com/azure/2017/11/22/the-wonderful-world-of-azure-cli-jmespath-queries/
I would appreciate your input.
Thank you
Upvotes: 1
Views: 998
Reputation: 72171
try doing it this way:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query `children`
and like this:
az account management-group show --name "Simple-NonProduction-EMG-v01" -e -r --query 'children[].name'
Upvotes: 1