Skip to content

Azure Resource Graph

Azure Resource Graph helps you explore and query your Azure resources efficiently and at scale. This guide covers installation, example queries, and best practices.


Requirements

To use Azure Resource Graph, ensure you have the following:

  • Azure PowerShell 1.0.0 or higher
  • PowerShellGet 2.0.1 or higher

Installation

Install the Module

Open an administrative terminal and run:

Install-Module -Name Az.ResourceGraph

Validate Installation

Check that the commands are available:

Get-Command -Module 'Az.ResourceGraph' -CommandType 'Cmdlet'

Example Queries

Query All Resources with a CreatedOnDate Tag

az graph query -q "Resources | where todatetime(tags.CreatedOnDate) < now(-30d) | project name"

Query All Resource Groups with a CreatedOnDate Tag

az graph query -q "ResourceContainers | where type=='microsoft.resources/subscriptions/resourcegroups' | where todatetime(tags.CreatedOnDate) < now(-30d) | project name"

Query Resources with Specific Tag Value

Search-AzGraph -Query "Resources | where tags.environment=~'internal' | project name"

Query All VMs Ordered by Name

Search-AzGraph -Query "Resources | project name, location, type| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"

References