Microsoft has documented pagination requirement with Search-AzGraph cmdlet
Documentation link : https://learn.microsoft.com/en-us/azure/governance/resource-graph/paginate-powershell?source=recommendations
Adding code below for reference in case in future links becomes inactive:
$kqlQuery = "Resources | join kind=leftouter (ResourceContainers | where
type=='microsoft.resources/subscriptions' | project subscriptionName = name, subscriptionId) on
subscriptionId | where type =~ 'Microsoft.Compute/virtualMachines' | project VMResourceId = id,
subscriptionName, resourceGroup, name"
$batchSize = 5
$skipResult = 0
[System.Collections.Generic.List[string]]$kqlResult
while ($true) {
if ($skipResult -gt 0) {
$graphResult = Search-AzGraph -Query $kqlQuery -First $batchSize -SkipToken $graphResult.SkipToken
}
else {
$graphResult = Search-AzGraph -Query $kqlQuery -First $batchSize
}
$kqlResult += $graphResult.data
if ($graphResult.data.Count -lt $batchSize) {
break;
}
$skipResult += $skipResult + $batchSize
}