Azure Resource Graph
2 minute read
Azure Resource Graph is an Azure service designed to extend Azure Resource Management by providing efficient and performant resource exploration with the ability to query at scale across a given set of subscriptions so that you can effectively govern your environment.
Resource types
Example queries
All resources with a CreatedOnDate tag
Azure Resource Graph Explorer
Resources
| where todatetime(tags.CreatedOnDate) <now(-30d)
Azure CLI
az graph query -q "Resources | where todatetime(tags.CreatedOnDate) <now(-30d) | project name"
Azure PowerShell
search-azgraph -query 'where todatetime(tags.CreatedOnDate) < now(-30d) | project name'
All resource groups with a CreatedOnDate tag
Azure Resource Graph Explorer
ResourceContainers
| where type =~ "microsoft.resources/subscriptions/resourcegroups"
| where todatetime(tags.CreatedOnDate) <now(-30d)
Azure CLI
az graph query -q "ResourceContainers | where type=='microsoft.resources/subscriptions/resourcegroups' | where todatetime(tags.CreatedOnDate) <now(-30d) | project name"
Azure PowerShell
az graph query -q "ResourceContainers | where type=='microsoft.resources/subscriptions/resourcegroups' | where todatetime(tags.CreatedOnDate) <now(-30d) | project name"
Resources with specific tag value
Azure PowerShell
Search-AzGraph -Query "Resources | where tags.environment=~'internal' | project name"
All VMs ordered by name
Azure PowerShell
Search-AzGraph -Query "Resources | project name, location, type| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
Install Azure Resource Graph module locally
To enable Azure PowerShell to query Azure Resource Graph, the module must be added. This module can be used with locally installed PowerShell.
Requirements
- Azure PowerShell 1.0.0 or higher (https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-8.0.0)
- PowerShellGet 2.0.1 or higher (https://docs.microsoft.com/en-us/powershell/scripting/gallery/installing-psget?view=powershell-7.2)
Install the module
- Open an administrative terminal and paste the following to install the module then check it’s installed
Install-Module -Name Az.ResourceGraph
- Validate that the commands are available
Get-Command -Module 'Az.ResourceGraph' -CommandType 'Cmdlet'
References
https://docs.microsoft.com/en-us/azure/governance/resource-graph/