|
1 | 1 | ---
|
2 | 2 | title: 'Paginate Azure Resource Graph query results using Azure PowerShell'
|
3 | 3 | description: In this quickstart, you control the volume Azure Resource Graph query output by using pagination in Azure PowerShell.
|
4 |
| -ms.date: 11/10/2022 |
| 4 | +ms.date: 11/11/2022 |
5 | 5 | ms.topic: quickstart
|
6 | 6 | ms.author: timwarner
|
7 | 7 | author: timwarner-msft
|
@@ -82,34 +82,34 @@ We'll then configure the query to return five records (VMs) at a time.
|
82 | 82 |
|
83 | 83 | 1. Update the query to implement the `skipToken` parameter and return 5 VMs in each batch:
|
84 | 84 |
|
85 |
| - ```powershell |
86 |
| -$kqlQuery = "Resources | join kind=leftouter (ResourceContainers | where |
87 |
| -type=='microsoft.resources/subscriptions' | project subscriptionName = name,subscriptionId) on |
88 |
| -subscriptionId | where type =~ 'Microsoft.Compute/virtualMachines' | project VMResourceId = id, |
89 |
| -subscriptionName, resourceGroup,name" |
| 85 | + ```powershell |
| 86 | + $kqlQuery = "Resources | join kind=leftouter (ResourceContainers | where |
| 87 | + type=='microsoft.resources/subscriptions' | project subscriptionName = name,subscriptionId) on |
| 88 | + subscriptionId | where type =~ 'Microsoft.Compute/virtualMachines' | project VMResourceId = id, |
| 89 | + subscriptionName, resourceGroup,name" |
90 | 90 |
|
91 |
| -$batchSize = 5 |
92 |
| -$skipResult = 0 |
| 91 | + $batchSize = 5 |
| 92 | + $skipResult = 0 |
93 | 93 |
|
94 |
| -[System.Collections.Generic.List[string]]$kqlResult |
| 94 | + [System.Collections.Generic.List[string]]$kqlResult |
95 | 95 |
|
96 |
| -while ($true) { |
| 96 | + while ($true) { |
97 | 97 |
|
98 |
| - if ($skipResult -gt 0) { |
99 |
| - $graphResult = Search-AzGraph -Query $kqlQuery -First $batchSize -SkipToken $graphResult.SkipToken |
100 |
| - } |
101 |
| - else { |
102 |
| - $graphResult = Search-AzGraph -Query $kqlQuery -First $batchSize |
103 |
| - } |
| 98 | + if ($skipResult -gt 0) { |
| 99 | + $graphResult = Search-AzGraph -Query $kqlQuery -First $batchSize -SkipToken $graphResult.SkipToken |
| 100 | + } |
| 101 | + else { |
| 102 | + $graphResult = Search-AzGraph -Query $kqlQuery -First $batchSize |
| 103 | + } |
104 | 104 |
|
105 |
| - $kqlResult += $graphResult.data |
| 105 | + $kqlResult += $graphResult.data |
106 | 106 |
|
107 |
| - if ($graphResult.data.Count -lt $batchSize) { |
108 |
| - break; |
| 107 | + if ($graphResult.data.Count -lt $batchSize) { |
| 108 | + break; |
| 109 | + } |
| 110 | + $skipResult += $skipResult + $batchSize |
109 | 111 | }
|
110 |
| - $skipResult += $skipResult + $batchSize |
111 |
| -} |
112 |
| - ``` |
| 112 | + ``` |
113 | 113 |
|
114 | 114 | ## Clean up resources
|
115 | 115 |
|
|
0 commit comments