Skip to content

Commit 836bd07

Browse files
Merge pull request #250035 from davidsmatlak/ds-arg-doc-update-0831
Adds summarize count scopes to ARG queries
2 parents 27a53fc + dbd5810 commit 836bd07

File tree

5 files changed

+154
-24
lines changed

5 files changed

+154
-24
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
ms.service: resource-graph
3+
ms.topic: include
4+
ms.date: 08/31/2023
5+
author: davidsmatlak
6+
ms.author: davidsmatlak
7+
---
8+
9+
### Summarize count
10+
11+
```kusto
12+
authorizationresources
13+
| summarize count()
14+
```
15+
16+
# [Azure CLI](#tab/azure-cli)
17+
18+
By default, Azure CLI queries all accessible subscriptions but you can specify the `--subscriptions` parameter to query specific subscriptions.
19+
20+
```azurecli-interactive
21+
az graph query -q "authorizationresources | summarize count()"
22+
```
23+
24+
This example uses a variable for the subscription ID.
25+
26+
```azurecli-interactive
27+
subid=$(az account show --query id --output tsv)
28+
az graph query -q "authorizationresources | summarize count()" --subscriptions $subid
29+
```
30+
31+
You can also query by the scopes for management group and tenant. Replace `<managementGroupId>` and `<tenantId>` with your values.
32+
33+
```azurecli-interactive
34+
az graph query -q "authorizationresources | summarize count()" --management-groups '<managementGroupId>'
35+
```
36+
37+
```azurecli-interactive
38+
az graph query -q "authorizationresources | summarize count()" --management-groups '<tenantId>'
39+
```
40+
41+
You can also use a variable for the tenant ID.
42+
43+
```azurecli-interactive
44+
tenantid=$(az account show --query tenantId --output tsv)
45+
az graph query -q "authorizationresources | summarize count()" --management-groups $tenantid
46+
```
47+
48+
# [Azure PowerShell](#tab/azure-powershell)
49+
50+
By default, Azure PowerShell gets results for all subscriptions in your tenant.
51+
52+
```azurepowershell-interactive
53+
Search-AzGraph -Query "authorizationresources | summarize count()"
54+
```
55+
56+
This example uses a variable to query a specific subscription ID.
57+
58+
```azurepowershell-interactive
59+
$subid = (Get-AzContext).Subscription.Id
60+
Search-AzGraph -Query "authorizationresources | summarize count()" -Subscription $subid
61+
```
62+
63+
You can query by the scopes for management group and tenant. Replace `<managementGroupId>`with your value. The `UseTenantScope` parameter doesn't require a value.
64+
65+
```azurepowershell-interactive
66+
Search-AzGraph -Query "authorizationresources | summarize count()" -ManagementGroup '<managementGroupId>'
67+
```
68+
69+
```azurepowershell-interactive
70+
Search-AzGraph -Query "authorizationresources | summarize count()" -UseTenantScope
71+
```
72+
73+
# [Portal](#tab/azure-portal)
74+
75+
:::image type="icon" source="../../../resource-graph/media/resource-graph-small.png"::: Try this query in Azure Resource Graph Explorer:
76+
77+
- Azure portal: <a href="https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/authorizationresources%0D%0A%7C%20summarize%20count%28%29" target="_blank">portal.azure.com</a>
78+
- Azure Government portal: <a href="https://portal.azure.us/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/authorizationresources%0D%0A%7C%20summarize%20count%28%29" target="_blank">portal.azure.us</a>
79+
- Microsoft Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/authorizationresources%0D%0A%7C%20summarize%20count%28%29" target="_blank">portal.azure.cn</a>
80+
81+
---
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
ms.service: resource-graph
33
ms.topic: include
4-
ms.date: 07/11/2023
4+
ms.date: 08/31/2023
55
author: davidsmatlak
66
ms.author: davidsmatlak
77
---
88

99
### Troubleshoot Azure RBAC limits
1010

11-
The `authorizationresources` table can be used to trouble Azure role-based access control (Azure RBAC) if you exceed limits. For more information, go to [Troubleshoot Azure RBAC limits](../../../../role-based-access-control/troubleshoot-limits.md).
11+
The `authorizationresources` table can be used to troubleshoot Azure role-based access control (Azure RBAC) if you exceed limits. For more information, go to [Troubleshoot Azure RBAC limits](../../../../role-based-access-control/troubleshoot-limits.md).

articles/governance/resource-graph/samples/samples-by-category.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Otherwise, use <kbd>Ctrl</kbd>-<kbd>F</kbd> to use your browser's search feature
5454

5555
## Azure RBAC
5656

57+
[!INCLUDE [authorization-resources-troubleshoot-rbac-limits](../../includes/resource-graph/query/authorization-resources-troubleshoot-rbac-limits.md)]
58+
5759
[!INCLUDE [authorization-resources-role-assignments-key-properties](../../includes/resource-graph/query/authorization-resources-role-assignments-key-properties.md)]
5860

5961
[!INCLUDE [authorization-resources-role-definitions-key-properties](../../includes/resource-graph/query/authorization-resources-role-definitions-key-properties.md)]
@@ -64,7 +66,7 @@ Otherwise, use <kbd>Ctrl</kbd>-<kbd>F</kbd> to use your browser's search feature
6466

6567
[!INCLUDE [authorization-resources-classic-administrators-key-properties](../../includes/resource-graph/query/authorization-resources-classic-administrators-key-properties.md)]
6668

67-
[!INCLUDE [authorization-resources-troubleshoot-rbac-limits](../../includes/resource-graph/query/authorization-resources-troubleshoot-rbac-limits.md)]
69+
[!INCLUDE [authorization-resources-summarize-count](../../includes/resource-graph/query/authorization-resources-summarize-count.md)]
6870

6971
## Azure Service Health
7072

articles/governance/resource-graph/samples/samples-by-table.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ details, see [Resource Graph tables](../concepts/query-language.md#resource-grap
1919

2020
## AuthorizationResources
2121

22+
[!INCLUDE [authorization-resources-troubleshoot-rbac-limits](../../includes/resource-graph/query/authorization-resources-troubleshoot-rbac-limits.md)]
23+
2224
[!INCLUDE [authorization-resources-role-assignments-key-properties](../../includes/resource-graph/query/authorization-resources-role-assignments-key-properties.md)]
2325

2426
[!INCLUDE [authorization-resources-role-definitions-key-properties](../../includes/resource-graph/query/authorization-resources-role-definitions-key-properties.md)]
@@ -29,7 +31,7 @@ details, see [Resource Graph tables](../concepts/query-language.md#resource-grap
2931

3032
[!INCLUDE [authorization-resources-classic-administrators-key-properties](../../includes/resource-graph/query/authorization-resources-classic-administrators-key-properties.md)]
3133

32-
[!INCLUDE [authorization-resources-troubleshoot-rbac-limits](../../includes/resource-graph/query/authorization-resources-troubleshoot-rbac-limits.md)]
34+
[!INCLUDE [authorization-resources-summarize-count](../../includes/resource-graph/query/authorization-resources-summarize-count.md)]
3335

3436
## ExtendedLocationResources
3537

articles/governance/resource-graph/samples/starter.md

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Starter query samples
33
description: Use Azure Resource Graph to run some starter queries, including counting resources, ordering resources, or by a specific tag.
44
author: davidsmatlak
55
ms.author: davidsmatlak
6-
ms.date: 07/19/2022
6+
ms.date: 08/31/2023
77
ms.topic: sample
88
ms.custom: devx-track-azurepowershell
99
---
@@ -15,7 +15,7 @@ The first step to understanding queries with Azure Resource Graph is a basic und
1515
[KQL tutorial](/azure/kusto/query/tutorial) to understand how to compose requests for the
1616
resources you're looking for.
1717

18-
We'll walk through the following starter queries:
18+
This article uses the following starter queries:
1919

2020
- [Count Azure resources](#count-resources)
2121
- [Count Key Vault resources](#count-keyvaults)
@@ -56,16 +56,61 @@ Resources
5656

5757
# [Azure CLI](#tab/azure-cli)
5858

59-
```azurecli
59+
By default, Azure CLI queries all accessible subscriptions but you can specify the `--subscriptions` parameter to query specific subscriptions.
60+
61+
```azurecli-interactive
6062
az graph query -q "Resources | summarize count()"
6163
```
6264

65+
This example uses a variable for the subscription ID.
66+
67+
```azurecli-interactive
68+
subid=$(az account show --query id --output tsv)
69+
az graph query -q "Resources | summarize count()" --subscriptions $subid
70+
```
71+
72+
You can also query by the scopes for management group and tenant. Replace `<managementGroupId>` and `<tenantId>` with your values.
73+
74+
```azurecli-interactive
75+
az graph query -q "Resources | summarize count()" --management-groups '<managementGroupId>'
76+
```
77+
78+
```azurecli-interactive
79+
az graph query -q "Resources | summarize count()" --management-groups '<tenantId>'
80+
```
81+
82+
You can also use a variable for the tenant ID.
83+
84+
```azurecli-interactive
85+
tenantid=$(az account show --query tenantId --output tsv)
86+
az graph query -q "Resources | summarize count()" --management-groups $tenantid
87+
```
88+
6389
# [Azure PowerShell](#tab/azure-powershell)
6490

91+
By default, Azure PowerShell gets results for all subscriptions in your tenant.
92+
6593
```azurepowershell-interactive
6694
Search-AzGraph -Query "Resources | summarize count()"
6795
```
6896

97+
This example uses a variable to query a specific subscription ID.
98+
99+
```azurepowershell-interactive
100+
$subid = (Get-AzContext).Subscription.Id
101+
Search-AzGraph -Query "authorizationresources | summarize count()" -Subscription $subid
102+
```
103+
104+
You can query by the scopes for management group and tenant. Replace `<managementGroupId>`with your value. The `UseTenantScope` parameter doesn't require a value.
105+
106+
```azurepowershell-interactive
107+
Search-AzGraph -Query "Resources | summarize count()" -ManagementGroup '<managementGroupId>'
108+
```
109+
110+
```azurepowershell-interactive
111+
Search-AzGraph -Query "Resources | summarize count()" -UseTenantScope
112+
```
113+
69114
# [Portal](#tab/azure-portal)
70115

71116
:::image type="icon" source="../media/resource-graph-small.png"::: Try this query in Azure Resource Graph Explorer:
@@ -89,7 +134,7 @@ Resources
89134

90135
# [Azure CLI](#tab/azure-cli)
91136

92-
```azurecli
137+
```azurecli-interactive
93138
az graph query -q "Resources | where type =~ 'microsoft.keyvault/vaults' | count"
94139
```
95140

@@ -123,7 +168,7 @@ Resources
123168

124169
# [Azure CLI](#tab/azure-cli)
125170

126-
```azurecli
171+
```azurecli-interactive
127172
az graph query -q "Resources | project name, type, location | order by name asc"
128173
```
129174

@@ -158,7 +203,7 @@ Resources
158203

159204
# [Azure CLI](#tab/azure-cli)
160205

161-
```azurecli
206+
```azurecli-interactive
162207
az graph query -q "Resources | project name, location, type| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
163208
```
164209

@@ -180,7 +225,7 @@ Search-AzGraph -Query "Resources | project name, location, type| where type =~ '
180225

181226
## <a name="show-sorted"></a>Show first five virtual machines by name and their OS type
182227

183-
This query will use `top` to only retrieve five matching records that are ordered by name. The type
228+
This query uses `top` to only retrieve five matching records that are ordered by name. The type
184229
of the Azure resource is `Microsoft.Compute/virtualMachines`. `project` tells Azure Resource Graph
185230
which properties to include.
186231

@@ -193,7 +238,7 @@ Resources
193238

194239
# [Azure CLI](#tab/azure-cli)
195240

196-
```azurecli
241+
```azurecli-interactive
197242
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project name, properties.storageProfile.osDisk.osType | top 5 by name desc"
198243
```
199244

@@ -230,7 +275,7 @@ Resources
230275

231276
# [Azure CLI](#tab/azure-cli)
232277

233-
```azurecli
278+
```azurecli-interactive
234279
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
235280
```
236281

@@ -263,7 +308,7 @@ Resources
263308

264309
# [Azure CLI](#tab/azure-cli)
265310

266-
```azurecli
311+
```azurecli-interactive
267312
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | extend os = properties.storageProfile.osDisk.osType | summarize count() by tostring(os)"
268313
```
269314

@@ -291,7 +336,7 @@ Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachi
291336
292337
## <a name="show-storage"></a>Show resources that contain storage
293338

294-
Instead of explicitly defining the type to match, this example query will find any Azure resource
339+
Instead of explicitly defining the type to match, this example query finds any Azure resource
295340
that `contains` the word **storage**.
296341

297342
```kusto
@@ -301,7 +346,7 @@ Resources
301346

302347
# [Azure CLI](#tab/azure-cli)
303348

304-
```azurecli
349+
```azurecli-interactive
305350
az graph query -q "Resources | where type contains 'storage' | distinct type"
306351
```
307352

@@ -335,7 +380,7 @@ Resources
335380

336381
# [Azure CLI](#tab/azure-cli)
337382

338-
```azurecli
383+
```azurecli-interactive
339384
az graph query -q "Resources | where type == 'microsoft.network/virtualnetworks' | extend subnets = properties.subnets | mv-expand subnets | project name, subnets.name, subnets.properties.addressPrefix, location, resourceGroup, subscriptionId"
340385
```
341386

@@ -371,7 +416,7 @@ Resources
371416

372417
# [Azure CLI](#tab/azure-cli)
373418

374-
```azurecli
419+
```azurecli-interactive
375420
az graph query -q "Resources | where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress) | project properties.ipAddress | limit 100"
376421
```
377422

@@ -403,7 +448,7 @@ Resources
403448

404449
# [Azure CLI](#tab/azure-cli)
405450

406-
```azurecli
451+
```azurecli-interactive
407452
az graph query -q "Resources | where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress) | summarize count () by subscriptionId"
408453
```
409454

@@ -437,7 +482,7 @@ Resources
437482

438483
# [Azure CLI](#tab/azure-cli)
439484

440-
```azurecli
485+
```azurecli-interactive
441486
az graph query -q "Resources | where tags.environment=~'internal' | project name"
442487
```
443488

@@ -468,7 +513,7 @@ Resources
468513

469514
# [Azure CLI](#tab/azure-cli)
470515

471-
```azurecli
516+
```azurecli-interactive
472517
az graph query -q "Resources | where tags.environment=~'internal' | project name, tags"
473518
```
474519

@@ -502,7 +547,7 @@ Resources
502547

503548
# [Azure CLI](#tab/azure-cli)
504549

505-
```azurecli
550+
```azurecli-interactive
506551
az graph query -q "Resources | where type =~ 'Microsoft.Storage/storageAccounts' | where tags['tag with a space']=='Custom value'"
507552
```
508553

@@ -555,7 +600,7 @@ ResourceContainers
555600

556601
# [Azure CLI](#tab/azure-cli)
557602

558-
```azurecli
603+
```azurecli-interactive
559604
az graph query -q "ResourceContainers | where isnotempty(tags) | project tags | mvexpand tags | extend tagKey = tostring(bag_keys(tags)[0]) | extend tagValue = tostring(tags[tagKey]) | union (resources | where notempty(tags) | project tags | mvexpand tags | extend tagKey = tostring(bag_keys(tags)[0]) | extend tagValue = tostring(tags[tagKey]) ) | distinct tagKey, tagValue | where tagKey !startswith "hidden-""
560605
```
561606

@@ -589,7 +634,7 @@ Resources
589634

590635
# [Azure CLI](#tab/azure-cli)
591636

592-
```azurecli
637+
```azurecli-interactive
593638
az graph query -q "Resources | where type =~ 'microsoft.network/networksecuritygroups' and isnull(properties.networkInterfaces) and isnull(properties.subnets) | project name, resourceGroup | sort by name asc"
594639
```
595640

0 commit comments

Comments
 (0)