You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/governance/resource-graph/concepts/explore-resources.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Explore your Azure resources
3
3
description: Learn to use the Resource Graph query language to explore your resources and discover how they're connected.
4
-
ms.date: 05/01/2021
4
+
ms.date: 05/11/2021
5
5
ms.topic: conceptual
6
6
---
7
7
# Explore your Azure resources with Resource Graph
@@ -18,8 +18,8 @@ the resource you're looking for.
18
18
19
19
### Virtual machine discovery
20
20
21
-
Let's start with a simple query to get a single VM from our environment and look at the properties
22
-
returned.
21
+
Let's start with a simple query to get a single virtual machine from our environment and look at the
22
+
properties returned.
23
23
24
24
```kusto
25
25
Resources
@@ -32,13 +32,14 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines'
32
32
```
33
33
34
34
```azurepowershell-interactive
35
-
Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | limit 1" | ConvertTo-Json -Depth 100
35
+
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | limit 1").Data | ConvertTo-Json -Depth 100
36
36
```
37
37
38
38
> [!NOTE]
39
-
> The Azure PowerShell `Search-AzGraph` cmdlet returns a **PSCustomObject** by default. To have the
40
-
> output look the same as what is returned by Azure CLI, the `ConvertTo-Json` cmdlet is used. The
41
-
> default value for **Depth** is _2_. Setting it to _100_ should convert all returned levels.
39
+
> The Azure PowerShell `Search-AzGraph` cmdlet returns a **PSResourceGraphResponse** by default. To
40
+
> have the output look the same as what is returned by Azure CLI, the `ConvertTo-Json` cmdlet is
41
+
> used on the **Data** property. The default value for **Depth** is _2_. Setting it to _100_ should
42
+
> convert all returned levels.
42
43
43
44
The JSON results are structured similar to the following example:
44
45
@@ -126,7 +127,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines'
126
127
```
127
128
128
129
```azurepowershell-interactive
129
-
Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location"
130
+
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location").Data | ConvertTo-Json
130
131
```
131
132
132
133
The JSON results are structured similar to the following example:
@@ -168,7 +169,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines'
168
169
```
169
170
170
171
```azurepowershell-interactive
171
-
Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' and properties.hardwareProfile.vmSize == 'Standard_B2s' | project name, resourceGroup"
172
+
(Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' and properties.hardwareProfile.vmSize == 'Standard_B2s' | project name, resourceGroup").Data | ConvertTo-Json
172
173
```
173
174
174
175
### Virtual machines connected to premium-managed disks
@@ -189,7 +190,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualmachines'
189
190
```
190
191
191
192
```azurepowershell-interactive
192
-
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"
193
+
(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
193
194
```
194
195
195
196
The result is a list of disk IDs.
@@ -229,7 +230,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/disks' and id ==
229
230
```
230
231
231
232
```azurepowershell-interactive
232
-
Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/disks' and id == '/subscriptions/<subscriptionId>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/ContosoVM1_OsDisk_1_9676b7e1b3c44e2cb672338ebe6f5166'"
233
+
(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
233
234
```
234
235
235
236
The JSON results are structured similar to the following example:
@@ -283,7 +284,7 @@ cat nics.txt
283
284
284
285
```azurepowershell-interactive
285
286
# Use Resource Graph to get all NICs and store in the $nics variable
286
-
$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"
287
+
$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
287
288
288
289
# Review the output of the query stored in the variable
289
290
$nics.nic
@@ -302,7 +303,7 @@ cat ips.txt
302
303
303
304
```azurepowershell-interactive
304
305
# Use Resource Graph with the $nics variable to get all related public IP addresses and store in $ips variable
305
-
$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"
306
+
$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
306
307
307
308
# Review the output of the query stored in the variable
308
309
$ips.publicIp
@@ -318,7 +319,7 @@ az graph query -q="Resources | where type =~ 'Microsoft.Network/publicIPAddresse
318
319
319
320
```azurepowershell-interactive
320
321
# Use Resource Graph with the $ips variable to get the IP address of the public IP address resources
321
-
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"
322
+
(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
322
323
```
323
324
324
325
To see how to accomplish these steps in a single query with the `join` operator, see the
0 commit comments