Skip to content

Commit 06a103f

Browse files
committed
adds query timeout, style edits
1 parent 8250df9 commit 06a103f

File tree

2 files changed

+122
-179
lines changed

2 files changed

+122
-179
lines changed

articles/governance/resource-graph/concepts/explore-resources.md

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
---
22
title: Explore your Azure resources
33
description: Learn to use the Resource Graph query language to explore your resources and discover how they're connected.
4-
ms.date: 12/18/2023
4+
ms.date: 06/03/2024
55
ms.topic: conceptual
66
ms.custom: devx-track-azurepowershell, devx-track-azurecli
77
---
88

99
# Explore your Azure resources with Resource Graph
1010

11-
Azure Resource Graph helps you explore and discover your Azure resources quickly and
12-
at scale. Engineered for fast responses, it's a great way to learn about your environment and also
13-
about the properties that exist on your Azure resources.
11+
Azure Resource Graph helps you explore and discover your Azure resources quickly and at scale. Engineered for fast responses, it's a great way to learn about your environment and also about the properties that exist on your Azure resources.
1412

1513
> [!NOTE]
1614
> Depending on the Resource Graph table, properties will either match the casing as shown in the Azure portal or be lowercased.
@@ -21,14 +19,11 @@ about the properties that exist on your Azure resources.
2119
2220
## Explore virtual machines
2321

24-
A common resource in Azure is a virtual machine. As a resource type, virtual machines have many
25-
properties that can be queried. Each property provides an option for filtering or finding exactly
26-
the resource you're looking for.
22+
A common resource in Azure is a virtual machine. As a resource type, virtual machines have many properties that can be queried. Each property provides an option for filtering or finding exactly the resource you're looking for.
2723

2824
### Virtual machine discovery
2925

30-
Let's start with a simple query to get a single virtual machine from our environment and look at the
31-
properties returned.
26+
Let's start with a simple query to get a single virtual machine from our environment and look at the properties returned.
3227

3328
```kusto
3429
Resources
@@ -40,14 +35,14 @@ Resources
4035
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | limit 1"
4136
```
4237

43-
```azurepowershell-interactive
38+
```azurepowershell
4439
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | limit 1").Data | ConvertTo-Json -Depth 100
4540
```
4641

4742
> [!NOTE]
48-
> The Azure PowerShell `Search-AzGraph` cmdlet returns a **PSResourceGraphResponse** by default. To
43+
> The Azure PowerShell `Search-AzGraph` cmdlet returns a `PSResourceGraphResponse` by default. To
4944
> have the output look the same as what is returned by Azure CLI, the `ConvertTo-Json` cmdlet is
50-
> used on the **Data** property. The default value for **Depth** is _2_. Setting it to _100_ should
45+
> used on the `Data` property. The default value for `Depth` is _2_. Setting it to _100_ should
5146
> convert all returned levels.
5247
5348
The JSON results are structured similar to the following example:
@@ -68,7 +63,7 @@ The JSON results are structured similar to the following example:
6863
"networkProfile": {
6964
"networkInterfaces": [
7065
{
71-
"id": "/subscriptions/<subscriptionId>/MyResourceGroup/providers/Microsoft.Network/networkInterfaces/contosovm1535",
66+
"id": "/subscriptions/<subscriptionId>/MyResourceGroup/providers/Microsoft.Network/networkInterfaces/contosovm2222",
7267
"resourceGroup": "MyResourceGroup"
7368
}
7469
]
@@ -96,15 +91,15 @@ The JSON results are structured similar to the following example:
9691
"createOption": "FromImage",
9792
"diskSizeGB": 127,
9893
"managedDisk": {
99-
"id": "/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166",
94+
"id": "/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_11111111111111111111111111111111",
10095
"resourceGroup": "MyResourceGroup",
10196
"storageAccountType": "Premium_LRS"
10297
},
103-
"name": "ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166",
98+
"name": "ContosoVM1_OsDisk_1_11111111111111111111111111111111",
10499
"osType": "Windows"
105100
}
106101
},
107-
"vmId": "bbb9b451-6dc7-4117-bec5-c971eb1118c6"
102+
"vmId": "11111111-1111-1111-1111-111111111111"
108103
},
109104
"resourceGroup": "MyResourceGroup",
110105
"sku": {},
@@ -115,15 +110,11 @@ The JSON results are structured similar to the following example:
115110
]
116111
```
117112

118-
The properties tell us additional information about the virtual machine resource itself. These
119-
properties include: operating system, disks, tags, and the resource group and subscription it's
120-
a member of.
113+
The properties tell us additional information about the virtual machine resource itself. These properties include: operating system, disks, tags, and the resource group and subscription it's a member of.
121114

122115
### Virtual machines by location
123116

124-
Taking what we learned about the virtual machines resource, let's use the **location** property to
125-
count all virtual machines by location. To update the query, we remove the limit and summarize
126-
the count of location values.
117+
Taking what we learned about the virtual machines resource, let's use the `location` property to count all virtual machines by location. To update the query, we remove the limit and summarize the count of location values.
127118

128119
```kusto
129120
Resources
@@ -135,7 +126,7 @@ Resources
135126
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location"
136127
```
137128

138-
```azurepowershell-interactive
129+
```azurepowershell
139130
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location").Data | ConvertTo-Json
140131
```
141132

@@ -162,8 +153,7 @@ We can now see how many virtual machines we have in each Azure region.
162153

163154
### Virtual machines by SKU
164155

165-
Going back to the original virtual machine properties, let's try to find all the virtual machines
166-
that have a SKU size of **Standard_B2s**. The returned JSON returned shows that it's stored in **properties.hardwareprofile.vmsize**. We'll update the query to find all VMs that match this size and return just the name of the VM and region.
156+
Going back to the original virtual machine properties, let's try to find all the virtual machines that have a SKU size of `Standard_B2s`. The returned JSON shows the value is stored in `properties.hardwareprofile.vmsize`. We update the query to find all virtual machines (VM) that match this size and return just the name of the VM and region.
167157

168158
```kusto
169159
Resources
@@ -175,14 +165,13 @@ Resources
175165
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' and properties.hardwareProfile.vmSize == 'Standard_B2s' | project name, resourceGroup"
176166
```
177167

178-
```azurepowershell-interactive
168+
```azurepowershell
179169
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' and properties.hardwareProfile.vmSize == 'Standard_B2s' | project name, resourceGroup").Data | ConvertTo-Json
180170
```
181171

182172
### Virtual machines connected to premium-managed disks
183173

184-
To get the details of premium-managed disks that are attached to these **Standard_B2s** virtual
185-
machines, we expand the query to return the resource ID of those managed disks.
174+
To get the details of premium-managed disks that are attached to these `Standard_B2s` virtual machines, we expand the query to return the resource ID of those managed disks.
186175

187176
```kusto
188177
Resources
@@ -196,60 +185,54 @@ Resources
196185
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualmachines' and properties.hardwareProfile.vmSize == 'Standard_B2s' | extend disk = properties.storageProfile.osDisk.managedDisk | where disk.storageAccountType == 'Premium_LRS' | project disk.id"
197186
```
198187

199-
```azurepowershell-interactive
188+
```azurepowershell
200189
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualmachines' and properties.hardwareProfile.vmSize == 'Standard_B2s' | extend disk = properties.storageProfile.osDisk.managedDisk | where disk.storageAccountType == 'Premium_LRS' | project disk.id").Data | ConvertTo-Json
201190
```
202191

203192
The result is a list of disk IDs.
204193

205194
### Managed disk discovery
206195

207-
With the first record from the previous query, we'll explore the properties that exist on the
208-
managed disk that was attached to the first virtual machine. The updated query uses the disk ID and
209-
changes the type.
196+
With the first record from the previous query, you explore the properties that exist on the managed disk that was attached to the first virtual machine. The updated query uses the disk ID and changes the type.
210197

211198
Example output from the previous query for example:
212199

213200
```json
214201
[
215202
{
216-
"disk_id": "/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166"
203+
"disk_id": "/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_11111111111111111111111111111111"
217204
}
218205
]
219206
```
220207

221208
```kusto
222209
Resources
223-
| where type =~ 'Microsoft.Compute/disks' and id == '/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166'
210+
| where type =~ 'Microsoft.Compute/disks' and id == '/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_11111111111111111111111111111111'
224211
```
225212

226-
Before you run the query, how did we know the **type** should now be **Microsoft.Compute/disks**? If
227-
you look at the full ID, you'll see **/providers/Microsoft.Compute/disks/** as part of the string.
228-
This string fragment gives you a hint as to what type to search for. An alternative method would be
229-
to remove the limit by type and instead only search by the ID field. As the ID is unique, only one
230-
record would be returned and the **type** property on it provides that detail.
213+
Before you run the query, how did we know the `type` should now be `Microsoft.Compute/disks`? If you look at the full ID, you notice `/providers/Microsoft.Compute/disks/` as part of the string. This string fragment gives you a hint as to what type to search for. An alternative method would be to remove the limit by type and instead only search by the ID field. As the ID is unique, only one record would be returned and the `type` property on it provides that detail.
231214

232215
> [!NOTE]
233216
> For this example to work, you must replace the ID field with a result from your own environment.
234217
235218
```azurecli
236-
az graph query -q "Resources | where type =~ 'Microsoft.Compute/disks' and id == '/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166'"
219+
az graph query -q "Resources | where type =~ 'Microsoft.Compute/disks' and id == '/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_11111111111111111111111111111111'"
237220
```
238221

239-
```azurepowershell-interactive
240-
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/disks' and id == '/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166'").Data | ConvertTo-Json
222+
```azurepowershell
223+
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/disks' and id == '/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_11111111111111111111111111111111'").Data | ConvertTo-Json
241224
```
242225

243226
The JSON results are structured similar to the following example:
244227

245228
```json
246229
[
247230
{
248-
"id": "/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166",
231+
"id": "/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_11111111111111111111111111111111",
249232
"kind": "",
250233
"location": "westus2",
251234
"managedBy": "",
252-
"name": "ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166",
235+
"name": "ContosoVM1_OsDisk_1_11111111111111111111111111111111",
253236
"plan": {},
254237
"properties": {
255238
"creationData": {
@@ -276,10 +259,7 @@ The JSON results are structured similar to the following example:
276259

277260
## Explore virtual machines to find public IP addresses
278261

279-
This set of queries first finds and stores all the network interfaces (NIC) resources connected to
280-
virtual machines. Then the queries use the list of NICs to find each IP address resource that is a
281-
public IP address and store those values. Finally, the queries provide a list of the public IP
282-
addresses.
262+
This set of queries first finds and stores all the network interface cards (NIC) resources connected to virtual machines. Then the queries use the list of NICs to find each IP address resource that is a public IP address and store those values. Finally, the queries provide a list of the public IP addresses.
283263

284264
```azurecli
285265
# Use Resource Graph to get all NICs and store in the 'nics.txt' file
@@ -289,16 +269,15 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines'
289269
cat nics.txt
290270
```
291271

292-
```azurepowershell-interactive
272+
```azurepowershell
293273
# Use Resource Graph to get all NICs and store in the $nics variable
294274
$nics = (Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project nic = tostring(properties['networkProfile']['networkInterfaces'][0]['id']) | where isnotempty(nic) | distinct nic | limit 20").Data
295275
296276
# Review the output of the query stored in the variable
297277
$nics.nic
298278
```
299279

300-
Use the file (Azure CLI) or variable (Azure PowerShell) in the next query to get the related network
301-
interface resources details where there's a public IP address attached to the NIC.
280+
In the next query, use the file (Azure CLI) or variable (Azure PowerShell), to get the related network interface card resources details that have a public IP address attached to the NIC.
302281

303282
```azurecli
304283
# Use Resource Graph with the 'nics.txt' file to get all related public IP addresses and store in 'publicIp.txt' file
@@ -308,30 +287,27 @@ az graph query -q="Resources | where type =~ 'Microsoft.Network/networkInterface
308287
cat ips.txt
309288
```
310289

311-
```azurepowershell-interactive
290+
```azurepowershell
312291
# Use Resource Graph with the $nics variable to get all related public IP addresses and store in $ips variable
313292
$ips = (Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Network/networkInterfaces' | where id in ('$($nics.nic -join "','")') | project publicIp = tostring(properties['ipConfigurations'][0]['properties']['publicIPAddress']['id']) | where isnotempty(publicIp) | distinct publicIp").Data
314293
315294
# Review the output of the query stored in the variable
316295
$ips.publicIp
317296
```
318297

319-
Last, use the list of public IP address resources stored in the file (Azure CLI) or variable (Azure
320-
PowerShell) to get the actual public IP address from the related object and display.
298+
Last, use the list of public IP address resources stored in the file (Azure CLI) or variable (Azure PowerShell) to get the actual public IP address from the related object and display.
321299

322300
```azurecli
323301
# Use Resource Graph with the 'ips.txt' file to get the IP address of the public IP address resources
324302
az graph query -q="Resources | where type =~ 'Microsoft.Network/publicIPAddresses' | where id in ('$(awk -vORS="','" '{print $0}' ips.txt | sed 's/,$//')') | project ip = tostring(properties['ipAddress']) | where isnotempty(ip) | distinct ip" --output table
325303
```
326304

327-
```azurepowershell-interactive
305+
```azurepowershell
328306
# Use Resource Graph with the $ips variable to get the IP address of the public IP address resources
329307
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Network/publicIPAddresses' | where id in ('$($ips.publicIp -join "','")') | project ip = tostring(properties['ipAddress']) | where isnotempty(ip) | distinct ip").Data | ConvertTo-Json
330308
```
331309

332-
To see how to accomplish these steps in a single query with the `join` operator, see the
333-
[List virtual machines with their network interface and public IP](../samples/advanced.md#list-virtual-machines-with-their-network-interface-and-public-ip)
334-
sample.
310+
To see how to accomplish these steps in a single query with the `join` operator, go to [List virtual machines with their network interface and public IP](../samples/advanced.md#list-virtual-machines-with-their-network-interface-and-public-ip) sample.
335311

336312
## Next steps
337313

0 commit comments

Comments
 (0)