Search code examples
azureazure-resource-groupazure-storage-account

Storage account can not be deleted with resource group


We wanted to delete a resource group that contained a VM with IP and storage account etc.

Everything got deleted except the storage account because of a vhd which says it still has a lease. I can't break the lease because of the following error message:

Failed to break lease on 1 out of 1 blob(s):
VM2X-20170518-074152.vhd: This blob is being used by the system.

Is there a way to break the lease, delete the blob with the lease active, or find out where it is leased to?

Additional Info: On the vhd on the "Edit blob" tab, I get the following message:

File size of '137.44GB' exceeds max supported file size of '2.1MB.'

Solution

  • This sounds like a familiar problem with classic storage accounts, if it's the problem I think it is you will need to delete image using Powershell.

    Set Storage account

    $storageAccountName = "your storage account"
    

    Check OS Disk image

    Get-AzureVmImage | Where-Object { $_.OSDiskConfiguration.MediaLink -ne $null -and $_.OSDiskConfiguration.MediaLink.Host.Contains($storageAccountName)`
                               } | Select-Object -Property ImageName, ImageLabel
    

    Check Data Disk image

    Get-AzureVmImage | Where-Object {$_.DataDiskConfigurations -ne $null `
                                        -and ($_.DataDiskConfigurations | Where-Object {$_.MediaLink -ne $null -and $_.MediaLink.Host.Contains($storageAccountName)}).Count -gt 0 `
                                       } | Select-Object -Property ImageName, ImageLabel
    

    Remove any image

    Remove-AzureVMImage -ImageName 'yourImageName'
    

    Note: commands are classic/ASM, make sure you have module installed.