Everything, Everything

2020: J F M A M J J
2019: J F M A M J J A S O N D
2018: J F M A M J J A S O N D
2017: J F M A M J J A S O N D
2016: J F M A M J J A S O N D
2015: J F M A M J J A S O N D
2014: J F M A M J J A S O N D
2013: J F M A M J J A S O N D
2012: J F M A M J J A S O N D
2011: J F M A M J J A S O N D
2010: J F M A M J J A S O N D
2009: J F M A M J J A S O N D
2008: J F M A M J J A S O N D
2007: J F M A M J J A S O N D
2006: J F M A M J J A S O N D
2005: J F M A M J J A S O N D
2004: J F M A M J J A S O N D
Unattached Disks in Azure
Wednesday 13th March, 2019 16:39 Comments: 0
I recently tried to delete all traces of a classic VM within Azure that I no longer require. Two out of three classic things were successful, but the storage account (and later on the resource group to which it belongs) couldn't be deleted because the storage account had some "active image(s) and/or disk(s)". The error code was the generic message "StorageAccountOperationFailed". Trying to find this unattached disk within the Azure portal seemed to be impossible. Thankfully after going into the storage account and selecting delete it then presented a checkbox to say it's okay to delete unattached disks (which it lists) when I delete the storage account. It appears that if I hadn't done this, I would continue to be charged for the unattached disk. This makes sense, but at the same time it shouldn't be so hard to find unattached disks!

What would be lovely is if the portal could show you all unattached disks. It can't. But a bunch of people have written various PowerShell scripts that can report or delete these for you.

But before I could do that, I needed to install Az. I previously had Azure installed (to set a reverse DNS entry on a host, because you can't do that through the portal either), and they can sort of co-exist. At some point I may run "Uninstall-AzureRm" to help keep things tidy. Anyway, this is how you install "Az" and check for unattached disks:

I launched an elevated Command Prompt then ran "powershell -ep bypass" so I can load scripts later on. Within PowerShell run:

Install-Module -Name Az -AllowClobber

This presents the warning:

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from

When prompted, select "[A] Yes to All" to trust the repository. Once complete, you need to authenticate:


Enter your credentials when prompted.

I saved the two scripts located on the Microsoft site as attached-unmanaged.ps1 and attached-managed.ps1 respectively and then ran them. Other similar scripts exist, but I'm going to trust a Microsoft page and not a random person's blog post.


I'm assuming that they both worked okay as I didn't get any output. I assume and hope that's because I don't have any unattached disks anymore.
© Robert Nicholls 2002-2020
The views and opinions expressed on this site do not represent the views of my employer.