Find unattached Azure disks
Documentation: Microsoft Learn
Get-AzDisk enumerates the managed disks in the subscription and Where-Object keeps those whose DiskState reads Unattached.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Get-AzDisk | Where-Object DiskState -eq Unattached | Select-Object Name,ResourceGroupName,DiskSizeGB,Sku- Stage 1Get-AzDisk
Positional values or no named parameters - Stage 2Where-Object
-eq - Stage 3Select-Object
Positional values or no named parameters
How it works
Get-AzDisk enumerates the managed disks in the subscription and Where-Object keeps those whose DiskState reads Unattached. The projection reports the name, resource group, provisioned size, and SKU, which together determine the monthly charge.
Adapting it
Add TimeCreated to the output and sort on it, because a disk unattached for six months is a different conversation from one detached during this morning's maintenance window.
Requirements
Az.Compute with a Connect-AzAccount session.
If the result is unexpected
A disk is flagged as unattached even though it may still be needed.
An absent VM attachment does not establish ownership, retention requirements or safe deletion.
- Inspect attachment metadata, tags, recent changes and the owning team's records.
Validate the result
Each candidate is confirmed as unattached and has an independent retention decision.
Keep the check reliable
Keep candidate discovery read-only and require owner review before removing disks.