Skip to content

Instantly share code, notes, and snippets.

@pmarques
Last active July 21, 2021 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarques/4cda638d6a5296050d98dc62fd221411 to your computer and use it in GitHub Desktop.
Save pmarques/4cda638d6a5296050d98dc62fd221411 to your computer and use it in GitHub Desktop.
Azure Resource Graph Queries
// Number of VMs by PowerState
// Filter per:
// * Management Group
// * Tags
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| where tags.service =~ "svc1" and tags.application in~ ("app1", "app2")
| join kind=inner (
ResourceContainers
| where type == "microsoft.resources/subscriptions" and properties.managementGroupAncestorsChain[0].name in ("staging", "prod")
| project subscriptionId
) on subscriptionId
| extend powerState = tostring(properties.extended.instanceView.powerState.code)
| summarize count() by powerState
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment