Find unattached Azure managed disks
On this page
List managed disks whose managedBy property is null in the subscription you choose. Review the returned disk IDs before deciding whether any disk should be removed.
Why this is worth a look
Unattached disks can continue to incur charges after a VM is deleted. Microsoft's discovery method checks managedBy: an attached managed disk contains a VM resource ID, while an unattached disk has a null value. This produces a review list, not a savings estimate.
Start with this query
BASHRun this Bash artifact with an authenticated Azure CLI session. Replace YOUR_SUBSCRIPTION_ID with the subscription to review. It lists managed disk IDs only and performs no changes.
#!/usr/bin/env bash
set -euo pipefail
# Replace this value before running the command.
SUBSCRIPTION_ID="YOUR_SUBSCRIPTION_ID"
az disk list \
--subscription "$SUBSCRIPTION_ID" \
--query '[?managedBy==`null`].[id]' \
--output tsvHow to confirm it
- 01
Choose the subscription
Replace YOUR_SUBSCRIPTION_ID before running the command. Azure CLI's --subscription option accepts a subscription name or ID; this example uses an ID.
- 02
Run the read-only inventory
Run the script with an authenticated Azure CLI identity that can list disks. The command examines managed disks in the selected subscription and returns IDs for the managedBy-null results.
- 03
Inspect before deciding
Keep the returned IDs for review. Use az disk show --ids with a complete returned resource ID to inspect a disk. LastOwnershipUpdateTime can be blank for a newly created disk until its state changes.
Before making changes
Assumptions: the placeholder is replaced with the intended subscription ID, Azure CLI is authenticated, and the identity can list disks. This is a point-in-time inventory with no pricing unit or time window and covers managed disks in that subscription only. A null VM reference does not establish that data can be discarded. It excludes unmanaged VHD page blobs in storage accounts.