azure finding and removing unattached disks

delete unattached disk in azure
azure identify unattached disks cost management
get azure managed disk powershell
azure unmanaged disk
detach disk from azure vm
azure managed disks
get-azdisk
azure os disk pricing

I am trying to find my disks on azure but I seem to only get one disk when I have around 20 atleast.

The Syntax:

Get-AzureDisk

Sadly, only one disk is showing which I beleive is from a classicVM.

Can someone help?

Just in case, the syntax to find unattached disk

Get-AzureDisk | Where-Object {$_.AttachedTo -eq $Null}

Was your VM deployed in Classic model or ARM model?

If the disks were attached to classic VM, and you selected a subscription which has these disks, you should be able to see all of them by Get-AzureDisk command. (The syntax you provided is correct.)

If the disks were attached to classic VM but you are not sure which subscription you have selected, see your current subscription by Get-AzureSubscription command. If you want to select other subscriptions, use Select-AzureSubscription command.

If your disks were detached from ARM VM or your ARM VM was deleted without deleting the disk, you can delete disks from Azure portal (https://portal.azure.com). Select Storage Accounts, then click on the storage account where your unattached VHD's are located, Click Blobs, click the container containing VHD, search for/click the vhd and click delete.

Note that there’s no direct PowerShell command for getting the Azure ARM VM disks. However, for existing VM and attached disks, you could use Get-AzureRmVM to return data disks as part of the VM return, then use Remove-AzureRmVMDataDisk command to delete ARM data disks. (This might not apply to your scenario since you are looking for unattached disks.)

Please be sure you select the right subscription and choose a corresponding command/action for different deployment models.

Let us know if it helps. Thanks!

Find and delete unattached Azure managed and unmanaged disks , Managed disks: Find and delete unattached disks. If you have unattached managed disks and no longer need the data on them, the following  If you have unattached managed disks and no longer need the data on them, the following process explains how to find them from the Azure portal: Sign in to the Azure portal. Search for and select Disks. On the Disks blade, you are presented with a list of all your disks. Any disk that has " -

The syntax looks correct to me. What do you see when you just run the Get-AzureDisk command? AzureDisk retrieves data for all the disks in the disk repository for the current subscription (https://msdn.microsoft.com/en-us/library/azure/dn495125.aspx). If the outputs from both command s(the one that you ran and the output of AzureDisks) are the same, you may have selected a subscription which do not have that many unattached disks.

Thanks, Aung

Identify unattached Azure disks - Azure portal, How to find and delete unattached Azure managed and unmanaged (VHDs/page blobs) disks by using Azure CLI. Whereas for deleting an Azure VM, having the VHD disk sitting unattached in Azure is a nice way to put it back together if the deletion was not accidental. In this post, I’m going to use Azure Storage Explorer to clean up a few disks from deleted Azure VMs. I like the Azure Storage Explorer tool, it’s a great additional administrative tool

The article includes scripts which should help you in achieving your requirement.

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/find-unattached-disks

# Managed disks: Find and delete unattached disks
#Set deleteUnattachedDisks=1 if you want to delete unattached Managed Disks
# Set deleteUnattachedDisks=0 if you want to see the Id of the unattached Managed Disks
$deleteUnattachedDisks=0

$managedDisks = Get-AzureRmDisk

foreach ($md in $managedDisks) {

    # ManagedBy property stores the Id of the VM to which Managed Disk is attached to
    # If ManagedBy property is $null then it means that the Managed Disk is not attached to a VM
    if($md.ManagedBy -eq $null){

        if($deleteUnattachedDisks -eq 1){

            Write-Host "Deleting unattached Managed Disk with Id: $($md.Id)"

            $md | Remove-AzureRmDisk -Force

            Write-Host "Deleted unattached Managed Disk with Id: $($md.Id) "

        }else{

            $md.Id

        }

    }

 }

Unmanaged disks: Find and delete unattached disks

# Set deleteUnattachedVHDs=1 if you want to delete unattached VHDs
# Set deleteUnattachedVHDs=0 if you want to see the Uri of the unattached VHDs
$deleteUnattachedVHDs=0

$storageAccounts = Get-AzureRmStorageAccount

foreach($storageAccount in $storageAccounts){

    $storageKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.StorageAccountName)[0].Value

    $context = New-AzureStorageContext -StorageAccountName $storageAccount.StorageAccountName -StorageAccountKey $storageKey

    $containers = Get-AzureStorageContainer -Context $context

    foreach($container in $containers){

        $blobs = Get-AzureStorageBlob -Container $container.Name -Context $context

        #Fetch all the Page blobs with extension .vhd as only Page blobs can be attached as disk to Azure VMs
        $blobs | Where-Object {$_.BlobType -eq 'PageBlob' -and $_.Name.EndsWith('.vhd')} | ForEach-Object { 

            #If a Page blob is not attached as disk then LeaseStatus will be unlocked
            if($_.ICloudBlob.Properties.LeaseStatus -eq 'Unlocked'){

                  if($deleteUnattachedVHDs -eq 1){

                        Write-Host "Deleting unattached VHD with Uri: $($_.ICloudBlob.Uri.AbsoluteUri)"

                        $_ | Remove-AzureStorageBlob -Force

                        Write-Host "Deleted unattached VHD with Uri: $($_.ICloudBlob.Uri.AbsoluteUri)"
                  }
                  else{

                        $_.ICloudBlob.Uri.AbsoluteUri

                  }

            }

        }

    }

}

Find and Delete Unused Azure Disks and Reduce Storage Costs, Learn how to find and delete unused disks in Azure and reduce storage if the VHD is unused, will show “Unattached” and blank respectively. By leveraging Azure Policies, we can easily raise the audit flag to identify when we have unattached disks, and then using the simple PowerShell scripts we can remove the disk files that are no longer needed. Using this process will help optimize your storage, and ensure you are only paying for resources you are using.

Identify and Manage Unattached Disks in Azure Storage : Mike , Identify and Manage Unattached Disks in Azure Storage /windows/find-​unattached-disks#managed-disks-find-and-delete-unattached-disks. in the ARM Azure portal. Select Storage Accounts, then click on the storage account" where your none used VHD's are located, Click Blobs under Services, click vhds under Essentials, search for unwanted vhd and click delete. If your VM deployed in classic portal, please refer below link to list the data disks:

Azure Cost Optimisation Series, After a VM is deleted, you will continue to pay for unattached disks. a “Delete Resource Lock” from the Azure Portal, find the Managed Disk  If this property is null, the NIC is not attached to a VM. To view all the unattached NICs, it's highly recommend to first run the script with the deleteUnattachedNics variable to 0. To delete all the unattached NICs after you review the list output, run the script with deleteUnattachedNics to 1. Azure CLI.

Using Azure Storage Explorer to remove unattached VM disks , Whereas for deleting an Azure VM, having the VHD disk sitting unattached in Azure is a nice way to put it back together if the deletion was not  Now that you know which disks are unused, you can simply select the disk and click on the delete button to delete it. Another way to use a GUI console to delete unused VHDs is by using the Azure portal. Use the Storage Accounts shortcut on your dashboard and drill down to the Blob container blade under the storage accounts presented there.

Comments
  • Thanks for responding. I was just looking for the powershell commmand but hopefully you guys would add one in the future.
  • Thanks for the feedback. The team is working on something similar to Get-AzureDisk. Please keep up with Azure PowerShell future releases. Thanks!
  • Hi,I am trying the Azure Web based CLI to find such unattached disks in my resource-group, but don't see the 'diskState' parameter in the response: I am in the Azure Web CLI console and executed the command "az disk list --resource-group XXXXXX --query '[].{name:name,diskState:diskState}' "