Created
October 28, 2026 08:55
-
-
Save markwragg/60a1483f612bcf8dcbde72d33fa8aba4 to your computer and use it in GitHub Desktop.
Unattached disks Azure resource graph KQL query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resources | |
| | where type =~ 'microsoft.compute/disks' | |
| | where tostring(properties.diskState) =~ 'Unattached' | |
| | where isempty(managedBy) | |
| // Exclude Azure Site Recovery replica disks, which are unattached by design | |
| | where isnull(tags['ASR-ReplicaDisk']) and name !endswith '-ASRReplica' | |
| | extend | |
| skuName = tostring(sku.name), | |
| sizeGB = toint(properties.diskSizeGB), | |
| created = todatetime(properties.timeCreated), | |
| lastDetached = todatetime(properties.LastOwnershipUpdateTime), | |
| owner = tostring(tags['owner']) | |
| | extend daysUnattached = datetime_diff('day', now(), coalesce(lastDetached, created)) | |
| | where daysUnattached >= 30 | |
| | join kind=leftouter ( | |
| resourcecontainers | |
| | where type =~ 'microsoft.resources/subscriptions' | |
| | project subscriptionId, subscriptionName = name | |
| ) on subscriptionId | |
| | project subscriptionName, resourceGroup, name, skuName, sizeGB, location, | |
| created, lastDetached, daysUnattached, owner, id | |
| | order by sizeGB desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment