Modules/Core/ARIInventoryLoop.psm1
<#
.Synopsis Azure Resource Graph loop module .DESCRIPTION This module is use to loop trough the Azure Resource Graph. .Link https://github.com/microsoft/ARI/Core/Invoke-ResourceInventory.psm1 .COMPONENT This powershell Module is part of Azure Resource Inventory (ARI) .NOTES Version: 4.0.1 First Release Date: 15th Oct, 2024 Authors: Claudio Merola #> function Invoke-ResourceInventoryLoop { param($GraphQuery,$FSubscri,$LoopName) Write-Progress -activity 'Azure Inventory' -Status "10% Complete." -PercentComplete 10 -CurrentOperation ('Extracting: ' + $LoopName) $LocalResults = @() if($FSubscri.count -gt 200) { $SubLoop = $FSubscri.count / 200 $SubLooper = 0 $NStart = 0 $NEnd = 200 while ($SubLooper -lt $SubLoop) { $Sub = $FSubscri[$NStart..$NEnd] try { $QueryResult = az graph query -q $GraphQuery --subscriptions $Sub --first 1000 --output json --only-show-errors | ConvertFrom-Json } catch { $QueryResult = az graph query -q $GraphQuery --subscriptions $Sub --first 200 --output json --only-show-errors | ConvertFrom-Json } $LocalResults += $QueryResult while ($QueryResult.skip_token) { try { $QueryResult = az graph query -q $GraphQuery --subscriptions $Sub --skip-token $QueryResult.skip_token --first 1000 --output json --only-show-errors | ConvertFrom-Json } catch { $QueryResult = az graph query -q $GraphQuery --subscriptions $Sub --skip-token $QueryResult.skip_token --first 200 --output json --only-show-errors | ConvertFrom-Json } $LocalResults += $QueryResult } $NStart = $NStart + 200 $NEnd = $NEnd + 200 $SubLooper ++ } } else { try { $QueryResult = az graph query -q $GraphQuery --subscriptions $FSubscri --first 1000 --output json --only-show-errors } catch { $QueryResult = az graph query -q $GraphQuery --subscriptions $FSubscri --first 200 --output json --only-show-errors } try { $QueryResult = $QueryResult | ConvertFrom-Json } catch { $QueryResult = $QueryResult | ConvertFrom-Json -AsHashtable } $LocalResults += $QueryResult while ($QueryResult.skip_token) { try { $QueryResult = az graph query -q $GraphQuery --subscriptions $FSubscri --skip-token $QueryResult.skip_token --first 1000 --output json --only-show-errors } catch { $QueryResult = az graph query -q $GraphQuery --subscriptions $FSubscri --skip-token $QueryResult.skip_token --first 200 --output json --only-show-errors } try { $QueryResult = $QueryResult | ConvertFrom-Json } catch { $QueryResult = $QueryResult | ConvertFrom-Json -AsHashtable } $LocalResults += $QueryResult } } $LocalResults.data } |