Azure Resource Graph Explorer


Use the Resource Graph Explorer to query VMs by subnet

Resources
| where type =~ 'Microsoft.Network/networkInterfaces'
| extend ipConfigs = properties.ipConfigurations
| mv-expand ipConfigs
| where ipConfigs.properties.subnet.id =~ '<subnet-resource-id>'
| project nicName = name, vmId = tostring(properties.virtualMachine.id)
| join kind=inner (
    Resources
    | where type =~ 'Microsoft.Compute/virtualMachines'
    | project vmId = id, vmName = name
) on vmId
| project vmName, nicName, vmId