Resource Graph query returning only 100 rows in output

D Mallikarjuna Reddy 96 Reputation points
2022-11-14T11:50:28.377+00:00

I am using Resource Graph Powershell module to query all the recent change details in my Subscription.

https://learn.microsoft.com/en-us/azure/governance/resource-graph/how-to/get-resource-changes?tabs=azure-powershell

But though there are many changes happened, the query is returning at max 100 at a time. So is there a way to get the complete records?

Is there a way to get all available records from Resource Graph module?

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,645 questions
{count} votes

Accepted answer
  1. Stanislav Zhelyazkov 28,186 Reputation points MVP Volunteer Moderator
    2022-11-16T09:32:23.89+00:00

    Hi,
    The correct way to get all records via Search-AzGraph cmdlet is to get this in batches. Meaning executing the command multiple times until you get all the results. What is important is to add sorting to your query like:

    $totalquery="resourcechanges  
    |extend changeType = tostring(properties.changeType), targetResourceType = tostring(properties.targetResourceType), changeTime = todatetime(properties.changeAttributes.timestamp)  
    | where targetResourceType !~ 'microsoft.web/connections  
    | sort by changeTime asc '"  
    

    After that the first command will be like

    $totalChanges = Search-AzGraph "$($totalquery)" -First 1000  
    

    After that you will need to check the count of $totalChanges.Count(). If the count is 1000 or higher you do another command:

     $totalChanges = Search-AzGraph "$($totalquery)" -First 1000 -Skip 1000  
    

    And you do the same until the count is not 1000 or higher. It is important that you add the results into one variable and to increase the skip number by 1000 every time you execute the query.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.