Skip to content

Commit 9dc10e0

Browse files
authored
Merge pull request #158144 from DCtheGeek/dmc-arg-ghi75055
Fix MicrosoftDocs/azure-docs#75055 - Update AzPS format for 0.10.0
2 parents a3520fc + 633be26 commit 9dc10e0

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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: 05/01/2021
4+
ms.date: 05/11/2021
55
ms.topic: conceptual
66
---
77
# Explore your Azure resources with Resource Graph
@@ -18,8 +18,8 @@ the resource you're looking for.
1818

1919
### Virtual machine discovery
2020

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.
2323

2424
```kusto
2525
Resources
@@ -32,13 +32,14 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines'
3232
```
3333

3434
```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
3636
```
3737

3838
> [!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.
4243
4344
The JSON results are structured similar to the following example:
4445

@@ -126,7 +127,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines'
126127
```
127128

128129
```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
130131
```
131132

132133
The JSON results are structured similar to the following example:
@@ -168,7 +169,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines'
168169
```
169170

170171
```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
172173
```
173174

174175
### Virtual machines connected to premium-managed disks
@@ -189,7 +190,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualmachines'
189190
```
190191

191192
```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
193194
```
194195

195196
The result is a list of disk IDs.
@@ -229,7 +230,7 @@ az graph query -q "Resources | where type =~ 'Microsoft.Compute/disks' and id ==
229230
```
230231

231232
```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
233234
```
234235

235236
The JSON results are structured similar to the following example:
@@ -283,7 +284,7 @@ cat nics.txt
283284

284285
```azurepowershell-interactive
285286
# 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
287288
288289
# Review the output of the query stored in the variable
289290
$nics.nic
@@ -302,7 +303,7 @@ cat ips.txt
302303

303304
```azurepowershell-interactive
304305
# 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
306307
307308
# Review the output of the query stored in the variable
308309
$ips.publicIp
@@ -318,7 +319,7 @@ az graph query -q="Resources | where type =~ 'Microsoft.Network/publicIPAddresse
318319

319320
```azurepowershell-interactive
320321
# 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
322323
```
323324

324325
To see how to accomplish these steps in a single query with the `join` operator, see the

articles/governance/resource-graph/first-query-powershell.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 'Quickstart: Your first PowerShell query'
33
description: In this quickstart, you follow the steps to enable the Resource Graph module for Azure PowerShell and run your first query.
4-
ms.date: 05/01/2021
4+
ms.date: 05/11/2021
55
ms.topic: quickstart
66
ms.custom:
77
- mode-api
@@ -49,7 +49,7 @@ The Resource Graph module for PowerShell is **Az.ResourceGraph**.
4949
Install-Module -Name Az.ResourceGraph
5050
```
5151

52-
1. Validate that the module has been imported and is the latest version (0.7.5):
52+
1. Validate that the module has been imported and is at least version `0.10.0`:
5353

5454
```azurepowershell-interactive
5555
# Get a list of commands for the imported Az.ResourceGraph module
@@ -68,18 +68,18 @@ Resource Graph query. The query returns the first five Azure resources with the
6868
# Login first with Connect-AzAccount if not using Cloud Shell
6969
7070
# Run Azure Resource Graph query
71-
Search-AzGraph -Query 'Resources | project name, type | limit 5'
71+
(Search-AzGraph -Query 'Resources | project name, type | limit 5').Data
7272
```
7373

7474
> [!NOTE]
75-
> As this query example does not provide a sort modifier such as `order by`, running this query
75+
> As this query example doesn't provide a sort modifier such as `order by`, running this query
7676
> multiple times is likely to yield a different set of resources per request.
7777
7878
1. Update the query to `order by` the **Name** property:
7979

8080
```azurepowershell-interactive
8181
# Run Azure Resource Graph query with 'order by'
82-
Search-AzGraph -Query 'Resources | project name, type | limit 5 | order by name asc'
82+
(Search-AzGraph -Query 'Resources | project name, type | limit 5 | order by name asc').Data
8383
```
8484

8585
> [!NOTE]
@@ -93,7 +93,7 @@ Resource Graph query. The query returns the first five Azure resources with the
9393

9494
```azurepowershell-interactive
9595
# Run Azure Resource Graph query with `order by` first, then with `limit`
96-
Search-AzGraph -Query 'Resources | project name, type | order by name asc | limit 5'
96+
(Search-AzGraph -Query 'Resources | project name, type | order by name asc | limit 5').Data
9797
```
9898

9999
When the final query is run several times, assuming that nothing in your environment is changing,

0 commit comments

Comments
 (0)