Open In App

Microsoft Azure – Find Orphaned Disks

In this article, you will see that how to find the unattached disks also known as orphaned disks in Azure. The main objective or purpose of deleting the orphaned resources is to save the cost of unused resources. When you delete a VM in Azure, the disks will not be deleted automatically and they will be left as orphaned disks.

Implementation:

Follow the below steps to find orphaned disks in Azure:



Step 1: Login to Azure Portal.

Step 2: Go to Azure Resource Graph Explorer >> select the Resource Graph Explorer



Step 3: Select Scope >> Subscription >> Select your subscriptions (You can select single or multiple subscriptions of your choice at once)

For Example: Here, I have selected 8 Subscriptions from Scope.

Step 4: Paste the below query in the query box and click on the Run query to get the list/report of unattached disks.

Example:

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

Output:

Example 1: If you have selected multiple subscriptions in scope then you will be getting many results >> In this case, you can add where subscriptionId has “_SubscriptionId_Value” to get the results in a particular select subscription.

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

Output:

Example 2: If you want results of tagged values to that orphaned disks then you can use the following kql command.

Resources
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState)
| where  diskState == 'Unattached' or managedBy == ""
| where subscriptionId == "" 
| where tags.Environment == "Production" // "Dev", "Prod", "Test",...etc.
| project name, diskState, managedBy, subscriptionId, resourceGroup, location, tags

Output:

That’s it you are done.

Article Tags :