Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
List, find, and discover Azure resources across subscriptions using Azure Resource Graph queries
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/azure-resource-graph.md
1# Azure Resource Graph Query Patterns23Azure Resource Graph (ARG) queries use a KQL subset against indexed Azure resource metadata. Results are near real-time across all subscriptions.45## Command Format67```bash8az graph query -q "<KQL>" --query "data[].{col1:field1, col2:field2}" -o table9```1011| Flag | Purpose |12|------|---------|13| `-q` | KQL query string |14| `--query` | JMESPath to shape output columns |15| `--first N` | Limit to N results |16| `--subscriptions` | Scope to specific subscription IDs |17| `-o table` | Table output (also: json, tsv) |1819## Key Tables2021| Table | Contents |22|-------|----------|23| `Resources` | All ARM resources — name, type, location, properties, tags, sku |24| `ResourceContainers` | Subscriptions, resource groups, management groups |25| `HealthResources` | Resource health availability status |26| `ServiceHealthResources` | Azure service health events/incidents |27| `AuthorizationResources` | Role assignments and definitions |28| `AdvisorResources` | Azure Advisor recommendations |2930## KQL Essentials3132- `=~` case-insensitive equals (use for `type` field — types are lowercase)33- `properties.fieldName` navigates the properties JSON bag34- `mv-expand` flattens arrays (subnets, IP configs)35- `isempty()` / `isnotnull()` checks for null/empty fields36- `tostring()` converts dynamic fields for display3738---3940## Resource Inventory Patterns4142**Count all resources by type:**43```kql44Resources | summarize count() by type | order by count_ desc45```4647**Inventory by type and location:**48```kql49Resources | summarize count() by type, location | order by type asc50```5152**Cross-subscription inventory with subscription names:**53```kql54Resources55| join kind=leftouter (56ResourceContainers57| where type == 'microsoft.resources/subscriptions'58| project subscriptionId, subscriptionName=name59) on subscriptionId60| summarize count() by subscriptionName, type61| order by subscriptionName asc, count_ desc62```6364**All resources in a resource group:**65```kql66Resources67| where resourceGroup =~ '<rg-name>'68| project name, type, location, sku.name, kind69```7071## Orphaned Resource Patterns7273**Unattached managed disks:**74```kql75Resources76| where type =~ 'microsoft.compute/disks'77| where isempty(managedBy)78| project name, resourceGroup, location, diskSizeGb=properties.diskSizeGB, sku=sku.name79```8081**Unused public IP addresses:**82```kql83Resources84| where type =~ 'microsoft.network/publicipaddresses'85| where isempty(properties.ipConfiguration)86| project name, resourceGroup, location, sku=sku.name87```8889**Orphaned network interfaces:**90```kql91Resources92| where type =~ 'microsoft.network/networkinterfaces'93| where isempty(properties.virtualMachine)94| project name, resourceGroup, location95```9697**Idle load balancers (no backends):**98```kql99Resources100| where type =~ 'microsoft.network/loadbalancers'101| where array_length(properties.backendAddressPools) == 0102| project name, resourceGroup, location103```104105## Tag & Compliance Patterns106107**Resources missing a required tag:**108```kql109Resources110| where isnull(tags['Environment']) or isnull(tags['CostCenter'])111| project name, type, resourceGroup, tags112```113114**Tag coverage analysis by type:**115```kql116Resources117| extend hasTag = isnotnull(tags['Environment'])118| summarize total=count(), tagged=countif(hasTag) by type119| extend coverage=round(100.0 * tagged / total, 1)120| order by coverage asc121```122123**Resources with public network access:**124```kql125Resources126| where properties.publicNetworkAccess =~ 'Enabled'127| project name, type, resourceGroup, location128```129130## Health & Diagnostics Patterns131132**Resource health status:**133```kql134HealthResources135| where type =~ 'microsoft.resourcehealth/availabilitystatuses'136| where properties.availabilityState != 'Available'137| project name, state=properties.availabilityState, reason=properties.reasonType138```139140**Active service health incidents:**141```kql142ServiceHealthResources143| where type =~ 'microsoft.resourcehealth/events'144| where properties.Status == 'Active'145| project name, title=properties.Title, status=properties.Status146```147148**Failed provisioning states:**149```kql150Resources151| where properties.provisioningState != 'Succeeded'152| project name, type, resourceGroup, state=properties.provisioningState153```154155## Service-Specific Patterns156157**App Services and their plans:**158```kql159Resources160| where type =~ 'microsoft.web/sites'161| project name, kind, location, plan=properties.serverFarmId, state=properties.state, resourceGroup162```163164**Container Apps:**165```kql166Resources167| where type =~ 'microsoft.app/containerapps'168| project name, location, provisioningState=properties.provisioningState, resourceGroup169```170171**VNet and subnet discovery:**172```kql173Resources174| where type =~ 'microsoft.network/virtualnetworks'175| mv-expand subnet=properties.subnets176| project vnetName=name, subnetName=subnet.name, prefix=subnet.properties.addressPrefix177```178179**Advisor cost recommendations:**180```kql181AdvisorResources182| where properties.category == 'Cost'183| project name, impact=properties.impact, solution=properties.shortDescription.solution184```185