Skip to content

Commit 4325201

Browse files
authored
Merge pull request #205237 from timwarner-msft/timwarner-listsubnets
Add new example query
2 parents 9a2de00 + 4525c6c commit 4325201

File tree

1 file changed

+39
-2
lines changed
  • articles/governance/resource-graph/samples

1 file changed

+39
-2
lines changed

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
---
22
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.
4-
ms.date: 07/07/2021
4+
author: timwarner-msft
5+
ms.author: timwarner
6+
ms.date: 07/19/2022
57
ms.topic: sample
68
---
79
# Starter Resource Graph query samples
810

911
The first step to understanding queries with Azure Resource Graph is a basic understanding of the
1012
[Query Language](../concepts/query-language.md). If you aren't already familiar with
1113
[Kusto Query Language (KQL)](/azure/kusto/query/index), it's recommended to review the
12-
[tutorial for KQL](/azure/kusto/query/tutorial) to understand how to compose requests for the
14+
[KQL tutorial](/azure/kusto/query/tutorial) to understand how to compose requests for the
1315
resources you're looking for.
1416

1517
We'll walk through the following starter queries:
@@ -21,6 +23,7 @@ We'll walk through the following starter queries:
2123
- [Show first five virtual machines by name and their OS type](#show-sorted)
2224
- [Count virtual machines by OS type](#count-os)
2325
- [Show resources that contain storage](#show-storage)
26+
- [List all virtual network subnets](#list-subnets)
2427
- [List all public IP addresses](#list-publicip)
2528
- [Count resources that have IP addresses configured by subscription](#count-resources-by-ip)
2629
- [List resources with a specific tag value](#list-tag)
@@ -317,6 +320,40 @@ Search-AzGraph -Query "Resources | where type contains 'storage' | distinct type
317320

318321
---
319322

323+
## <a name="list-subnets"></a>List all Azure virtual network subnets
324+
325+
This query returns a list of Azure virtual networks (VNets) including subnet names and address prefixes. Thanks to [Saul Dolgin](https://github.com/sdolgin) for the contribution.
326+
327+
```kusto
328+
Resources
329+
| where type == 'microsoft.network/virtualnetworks'
330+
| extend subnets = properties.subnets
331+
| mv-expand subnets
332+
| project name, subnets.name, subnets.properties.addressPrefix, location, resourceGroup, subscriptionId
333+
```
334+
335+
# [Azure CLI](#tab/azure-cli)
336+
337+
```azurecli
338+
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"
339+
```
340+
341+
# [Azure PowerShell](#tab/azure-powershell)
342+
343+
```azurepowershell-interactive
344+
Search-AzGraph -Query "Resources | where type == 'microsoft.network/virtualnetworks' | extend subnets = properties.subnets | mv-expand subnets | project name, subnets.name, subnets.properties.addressPrefix, location, resourceGroup, subscriptionId
345+
```
346+
347+
# [Portal](#tab/azure-portal)
348+
349+
:::image type="icon" source="../media/resource-graph-small.png"::: Try this query in Azure Resource Graph Explorer:
350+
351+
- Azure portal: <a href="https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/Resources%0A%7C%20where%20type%20%3D%3D%20%27microsoft.network%2Fvirtualnetworks%27%0A%7C%20extend%20subnets%20%3D%20properties.subnets%0A%7C%20mv-expand%20subnets%0A%7C%20project%20name%2C%20subnets.name%2C%20subnets.properties.addressPrefix%2C%20location%2C%20resourceGroup%2C%20subscriptionId" target="_blank">portal.Azure.com</a>
352+
- Azure Government portal: <a href="https://portal.azure.us/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/Resources%0A%7C%20where%20type%20%3D%3D%20%27microsoft.network%2Fvirtualnetworks%27%0A%7C%20extend%20subnets%20%3D%20properties.subnets%0A%7C%20mv-expand%20subnets%0A%7C%20project%20name%2C%20subnets.name%2C%20subnets.properties.addressPrefix%2C%20location%2C%20resourceGroup%2C%20subscriptionId" target="_blank">portal.Azure.us</a>
353+
- Azure China 21Vianet portal: <a href="https://portal.azure.cn/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/Resources%0A%7C%20where%20type%20%3D%3D%20%27microsoft.network%2Fvirtualnetworks%27%0A%7C%20extend%20subnets%20%3D%20properties.subnets%0A%7C%20mv-expand%20subnets%0A%7C%20project%20name%2C%20subnets.name%2C%20subnets.properties.addressPrefix%2C%20location%2C%20resourceGroup%2C%20subscriptionId" target="_blank">portal.Azure.cn</a>
354+
355+
---
356+
320357
## <a name="list-publicip"></a>List all public IP addresses
321358

322359
Similar to the previous query, find everything that is a type with the word **publicIPAddresses**.

0 commit comments

Comments
 (0)