Skip to content

Commit 78f5681

Browse files
authored
Service Groups ARG sample queries
1 parent bd14e77 commit 78f5681

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
author: kenieva
3+
ms.service: resource-graph
4+
ms.topic: include
5+
ms.date: 06/20/2025
6+
ms.author: kenieva
7+
---
8+
9+
### List of all Service Group
10+
11+
Outputs a list of Service Groups.
12+
13+
```kusto
14+
resourcecontainers
15+
| where type == "microsoft.management/servicegroups"
16+
```
17+
18+
# [Azure CLI](#tab/azure-cli)
19+
20+
```azurecli-interactive
21+
az graph query -q "resourcecontainers | where type == 'microsoft.management/servicegroups'"
22+
```
23+
24+
# [Azure PowerShell](#tab/azure-powershell)
25+
26+
```azurepowershell-interactive
27+
Search-AzGraph -Query "resourcecontainers | where type == 'microsoft.management/servicegroups'" -UseTenantScope
28+
```
29+
30+
# [Portal](#tab/azure-portal)
31+
32+
- Azure portal: <a href="https://portal.azure.com/#blade/HubsExtension/ArgQueryBlade/query/ResourceContainers%0a%7c%20where%20type%20%3d%7e%20%27microsoft.management%2fmanagementgroups%27%0a%7c%20project%20mgname%20%3d%20name%0a%7c%20join%20kind%3dleftouter%20(resourcecontainers%20%7c%20where%20type%3d%7e%20%27microsoft.resources%2fsubscriptions%27%0a%7c%20extend%20%20mgParent%20%3d%20properties.managementGroupAncestorsChain%20%7c%20project%20id%2c%20mgname%20%3d%20tostring(mgParent%5b0%5d.name))%20on%20mgname%0a%7c%20summarize%20count()%20by%20mgname](https://ms.portal.azure.com/#view/HubsExtension/ArgQueryBlade/query/resourcecontainers%0A%7C%20where%20type%20%3D%3D%20%22microsoft.management%2Fservicegroups%22)" target="_blank">portal.azure.com</a>
33+
34+
---
35+
36+
### List of all members for a particular Service Group
37+
38+
Outputs a list of resource IDs that are members for a particular Service Groups. In this example, the service group ID is '123'.
39+
40+
```kusto
41+
relationshipresources
42+
    | where type == "microsoft.relationships/servicegroupmember"
43+
| where properties.TargetId == '/providers/Microsoft.Management/serviceGroups/123'
44+
| project properties.SourceId
45+
```
46+
47+
# [Azure CLI](#tab/azure-cli)
48+
49+
```azurecli-interactive
50+
az graph query -q "relationshipresources| where type == 'microsoft.relationships/servicegroupmember'| where properties.TargetId == '/providers/Microsoft.Management/serviceGroups/123' | project properties.SourceId"
51+
```
52+
53+
# [Azure PowerShell](#tab/azure-powershell)
54+
55+
```azurepowershell-interactive
56+
Search-AzGraph -Query "relationshipresources| where type == 'microsoft.relationships/servicegroupmember'| where properties.TargetId == '/providers/Microsoft.Management/serviceGroups/123' | project properties.SourceId" -UseTenantScope
57+
```
58+
59+
# [Portal](#tab/azure-portal)
60+
61+
- Azure portal: <a href="https://portal.azure.com/#blade/HubsExtension/ArgQueryBlade/query/relationshipresources%7C%20where%20type%20%3D%3D%20'microsoft.relationships%2Fservicegroupmember'%7C%20where%20properties.TargetId%20%3D%3D%20'%2Fproviders%2FMicrosoft.Management%2FserviceGroups%2F123'%20%7C%20project%20properties.SourceId" target="_blank">portal.azure.com</a>
62+
63+
---
64+
65+
### Count of Members for all Service Groups
66+
67+
Provides a count of service group members for a particular service group. In this example, the service group ID is '123'.
68+
69+
```kusto
70+
relationshipresources
71+
    | where type == "microsoft.relationships/servicegroupmember"
72+
| where properties.TargetId == '/providers/Microsoft.Management/serviceGroups/123'
73+
| count
74+
```
75+
76+
# [Azure CLI](#tab/azure-cli)
77+
78+
```azurecli-interactive
79+
az graph query -q "relationshipresources| where type == 'microsoft.relationships/servicegroupmember'| where properties.TargetId == '/providers/Microsoft.Management/serviceGroups/123' | count"
80+
```
81+
82+
# [Azure PowerShell](#tab/azure-powershell)
83+
84+
```azurepowershell-interactive
85+
Search-AzGraph -Query "relationshipresources| where type == 'microsoft.relationships/servicegroupmember'| where properties.TargetId == '/providers/Microsoft.Management/serviceGroups/123' | count" -UseTenantScope
86+
```
87+
88+
# [Portal](#tab/azure-portal)
89+
90+
- Azure portal: <a href="https://portal.azure.com/#blade/HubsExtension/ArgQueryBlade/query/relationshipresources%7C%20where%20type%20%3D%3D%20'microsoft.relationships%2Fservicegroupmember'%7C%20where%20properties.TargetId%20%3D%3D%20'%2Fproviders%2FMicrosoft.Management%2FserviceGroups%2F123'%20%7C%20count" target="_blank">portal.azure.com</a>
91+
92+
---
93+
94+
### Count members per Service Group
95+
96+
Provides the number of relationships per existing Service Group.
97+
98+
```kusto
99+
resourcecontainers
100+
| where type == "microsoft.management/servicegroups"
101+
| project SGName = ['id']
102+
| join kind=inner (
103+
    relationshipresources
104+
    | where type == "microsoft.relationships/servicegroupmember"
105+
    | project TargetID = tostring(properties.TargetId), relationshipid = tostring(id)
106+
) on $left.SGName == $right.TargetID
107+
|project SGName, relationshipid
108+
```
109+
110+
# [Azure CLI](#tab/azure-cli)
111+
112+
```azurecli-interactive
113+
az graph query -q "ResourceContainers | where type =~ 'microsoft.resources/subscriptions' | extend mgParent = properties.managementGroupAncestorsChain | mv-expand with_itemindex=MGHierarchy mgParent | project subscriptionId, name, mgParent, MGHierarchy, mgParent.name" --subscriptions 11111111-1111-1111-1111-111111111111
114+
```
115+
116+
# [Azure PowerShell](#tab/azure-powershell)
117+
118+
```azurepowershell-interactive
119+
Search-AzGraph -Query "ResourceContainers | where type =~ 'microsoft.resources/subscriptions' | extend mgParent = properties.managementGroupAncestorsChain | mv-expand with_itemindex=MGHierarchy mgParent | project subscriptionId, name, mgParent, MGHierarchy, mgParent.name" -Subscription 11111111-1111-1111-1111-111111111111
120+
```
121+
122+
# [Portal](#tab/azure-portal)
123+
124+
125+
126+
- Azure portal: <a href="https://portal.azure.com/#blade/HubsExtension/ArgQueryBlade/query/ResourceContainers%0a%7c%20where%20type%20%3d%7e%20%27microsoft.resources%2fsubscriptions%27%0a%7c%20extend%20%20mgParent%20%3d%20properties.managementGroupAncestorsChain%0a%7c%20mv-expand%20with_itemindex%3dMGHierarchy%20mgParent%0a%7c%20project%20subscriptionId%2c%20name%2c%20mgParent%2c%20MGHierarchy%2c%20mgParent.name" target="_blank">portal.azure.com</a>
127+
- Azure Government portal: <a href="https://portal.azure.us/#blade/HubsExtension/ArgQueryBlade/query/ResourceContainers%0a%7c%20where%20type%20%3d%7e%20%27microsoft.resources%2fsubscriptions%27%0a%7c%20extend%20%20mgParent%20%3d%20properties.managementGroupAncestorsChain%0a%7c%20mv-expand%20with_itemindex%3dMGHierarchy%20mgParent%0a%7c%20project%20subscriptionId%2c%20name%2c%20mgParent%2c%20MGHierarchy%2c%20mgParent.name" target="_blank">portal.azure.us</a>
128+
- Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/#blade/HubsExtension/ArgQueryBlade/query/ResourceContainers%0a%7c%20where%20type%20%3d%7e%20%27microsoft.resources%2fsubscriptions%27%0a%7c%20extend%20%20mgParent%20%3d%20properties.managementGroupAncestorsChain%0a%7c%20mv-expand%20with_itemindex%3dMGHierarchy%20mgParent%0a%7c%20project%20subscriptionId%2c%20name%2c%20mgParent%2c%20MGHierarchy%2c%20mgParent.name" target="_blank">portal.azure.cn</a>
129+
130+
---
131+
132+
### Count Membership of Service Group per resource
133+
134+
Provides the number of relationships per existing Service Group.
135+
136+
```kusto
137+
resourcecontainers
138+
| where type == "microsoft.management/servicegroups"
139+
| project SGName = ['id']
140+
| join kind=inner (
141+
    relationshipresources
142+
    | where type == "microsoft.relationships/servicegroupmember"
143+
    | project TargetID = tostring(properties.TargetId), relationshipid = tostring(id)
144+
) on $left.SGName == $right.TargetID
145+
|project SGName, relationshipid
146+
```
147+
148+
# [Azure CLI](#tab/azure-cli)
149+
150+
```azurecli-interactive
151+
az graph query -q "ResourceContainers | where type =~ 'microsoft.resources/subscriptions' | extend mgParent = properties.managementGroupAncestorsChain | mv-expand with_itemindex=MGHierarchy mgParent | project subscriptionId, name, mgParent, MGHierarchy, mgParent.name" --subscriptions 11111111-1111-1111-1111-111111111111
152+
```
153+
154+
# [Azure PowerShell](#tab/azure-powershell)
155+
156+
```azurepowershell-interactive
157+
Search-AzGraph -Query "ResourceContainers | where type =~ 'microsoft.resources/subscriptions' | extend mgParent = properties.managementGroupAncestorsChain | mv-expand with_itemindex=MGHierarchy mgParent | project subscriptionId, name, mgParent, MGHierarchy, mgParent.name" -Subscription 11111111-1111-1111-1111-111111111111
158+
```
159+
160+
# [Portal](#tab/azure-portal)
161+
162+
163+
164+
- Azure portal: <a href="https://portal.azure.com/#blade/HubsExtension/ArgQueryBlade/query/ResourceContainers%0a%7c%20where%20type%20%3d%7e%20%27microsoft.resources%2fsubscriptions%27%0a%7c%20extend%20%20mgParent%20%3d%20properties.managementGroupAncestorsChain%0a%7c%20mv-expand%20with_itemindex%3dMGHierarchy%20mgParent%0a%7c%20project%20subscriptionId%2c%20name%2c%20mgParent%2c%20MGHierarchy%2c%20mgParent.name" target="_blank">portal.azure.com</a>
165+
- Azure Government portal: <a href="https://portal.azure.us/#blade/HubsExtension/ArgQueryBlade/query/ResourceContainers%0a%7c%20where%20type%20%3d%7e%20%27microsoft.resources%2fsubscriptions%27%0a%7c%20extend%20%20mgParent%20%3d%20properties.managementGroupAncestorsChain%0a%7c%20mv-expand%20with_itemindex%3dMGHierarchy%20mgParent%0a%7c%20project%20subscriptionId%2c%20name%2c%20mgParent%2c%20MGHierarchy%2c%20mgParent.name" target="_blank">portal.azure.us</a>
166+
- Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/#blade/HubsExtension/ArgQueryBlade/query/ResourceContainers%0a%7c%20where%20type%20%3d%7e%20%27microsoft.resources%2fsubscriptions%27%0a%7c%20extend%20%20mgParent%20%3d%20properties.managementGroupAncestorsChain%0a%7c%20mv-expand%20with_itemindex%3dMGHierarchy%20mgParent%0a%7c%20project%20subscriptionId%2c%20name%2c%20mgParent%2c%20MGHierarchy%2c%20mgParent.name" target="_blank">portal.azure.cn</a>
167+
168+
---
169+

0 commit comments

Comments
 (0)