Forum Topic

Thanks for your participation and contribution.


Back to Log Analytics

Azure Graph Queries Collection

i90runner1
i90runner1

Source : https://www.cloudsma.com/2021/02/find-orphaned-azure-resources/

Find Orphaned Disks

Resources
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState)
| where managedBy == ""
or diskState == 'Unattached'
| project id, diskState, resourceGroup, location, subscriptionId , sku.tier , properties.diskSizeGB

Find Orphaned NICs

Resources
| where type has "microsoft.network/networkinterfaces"
| where "{nicWithPrivateEndpoints}" !has id
| where properties !has 'virtualmachine'
| project id, resourceGroup, location, subscriptionId

NSGs

This query isn’t technically an orphaned resource, however if you make an NSG you typically want it applied to a NIC or subnet. This query looks through the Network/networksecuritygroups resource type and looks for null network interfaces and subnets under the properties.

Resources
| where type =~ 'microsoft.network/networksecuritygroups' and isnull(properties.networkInterfaces) and isnull(properties.subnets)
| project Resource=id, resourceGroup, subscriptionId, location

Last updated

1-1 of 1

Reply to this discussion

You cannot edit posts or make replies: You should be logged in before you can post.