Skip to content

Instantly share code, notes, and snippets.

@caseywatson
Created March 21, 2024 16:51
Show Gist options
  • Select an option

  • Save caseywatson/81e575e0f3745065e2a5ac59dd59e23d to your computer and use it in GitHub Desktop.

Select an option

Save caseywatson/81e575e0f3745065e2a5ac59dd59e23d to your computer and use it in GitHub Desktop.
Groups VMs based on VM name using the beginning letters to the first digit to determine if vmGroup is spread across two or more availability zones. For output, it includes the tag, Application Name.
resources
| where type =~ 'microsoft.compute/virtualmachines'
| project vmId = id, vmName = name, vmZone = tostring(zones[0]), vmGroup = trim_end('\\d+$', name), appName = tags['Application Name'], location
| summarize vmCount = count(), zoneCount = dcountif(vmZone, isnotempty(vmZone)) by vmGroup
| where zoneCount < min_of(vmCount, 2)
| join kind=inner(
resources
| where type=~ 'microsoft.compute/virtualmachines'
| project vmId = id, vmName = name, vmZone = tostring(zones[0]), vmGroup = trim_end('\\d+$', name), appName = tags['Application Name'], location) on vmGroup
| project vmGroup, vmName, location, vmZone, vmId, appName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment