Going to maintain a running post of userful Azure Resource Graph queries for my own reference.
Getting a list of all VMs created in the last 15 days
1 2 3 |
Resources | where type == 'microsoft.compute/virtualmachines' and properties.timeCreated > ago(15day) | project name,properties.timeCreated |
Subnets and Address Prefixes
This gives a list of subnets and address prefixes.
1 2 3 4 5 |
Resources | where type =~ 'microsoft.network/virtualnetworks' | project subnets = properties.subnets | mvexpand subnets | project subnets.name, addressPrefix = subnets.properties.addressPrefix |
This adds the vnet name too, to the subnet.
1 2 3 4 5 |
Resources | where type =~ 'microsoft.network/virtualnetworks' | project virtualNetwork = name, subnets = properties.subnets | mvexpand subnets | project vnetSubnet = tolower(strcat(virtualNetwork, "-", subnets.name)), addressPrefix = subnets.properties.addressPrefix |
This gives me subscription Id too.
1 2 3 4 5 |
Resources | where type =~ 'microsoft.network/virtualnetworks' | project subscriptionId, virtualNetwork = name, subnets = properties.subnets | mvexpand subnets | project subscriptionId, vnetSubnet = tolower(strcat(virtualNetwork, "-", subnets.name)), addressPrefix = subnets.properties.addressPrefix |
Public IPs
This gives me public IPs and what it is assigned to.
1 2 3 4 5 |
Resources | where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress) | extend ipConfig = properties.ipConfiguration.id | extend ipAddress = properties.ipAddress | project ipAddress, ipConfig |
The output needs some work. ipConfig
is currently /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Network/networkInterfaces/<nic>/ipConfigurations/ipconfig1
. I should split or do other things with it.