Hello @Shripad Limaye ,
Based upon your multiple requirements I am providing you couple of bits and pieces of the azure powershell commands which you can combine and leverage to-gether:
1) To Get list of all the Disks and their Corresponding Virtual Machine names you can use the below command:
Get-AzureRmDisk | Select Name , ManagedBy
(ManagedBy column denotes which Disk is being used by which Virtual Machine)
(You can apply the filters for the above command like: Get-AzureRmDisk | where -FilterScript {$_.ManagedBy -contains "something"} | select Name , ManagedBy )
Sample Output:
2 . To Identity the VMs and their Corresponding disks
$vms = Get-AzureRmVM // To get all the VMs
$vm = Get-AzureRMVM -Name $vms[0].Name -ResourceGroupName $vms[0].ResourceGroupName //Get one of the VM details
$vm.StorageProfile //It will show OsDisk & DataDisk
You can loop through all the VMs & Corresponding Disks:
** Finally use Remove-AzureRmDisk by providing the ResourceGroup and Disk Name.**
You can combine all those 3 commands. I think you will have a good script as per your requirements.
Kindly let us know if you have additional questions !