AzureCompute3 min read

Find unattached Azure managed disks

Sources checked September 7, 202610 minutes
On this page
THE SHORT ANSWER

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

BASH

Run 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.

List disk IDs without deleting anything
#!/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 tsv

How to confirm it

  1. 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.

  2. 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.

  3. 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.

Ignore this check if you need unmanaged VHDs in storage accounts; use Microsoft's separate procedure, which checks page-blob LeaseStatus instead.

Primary sources