Parallel Delete Azure RM Virtual Machine-NIC-Disks (Updated Sept 2019)

Parallel Delete Virtual Machines in Azure This script will delete an Azure Resource manager Virtual Machine. It will also delete the associated Network Interface Card (NIC). It will also remote both STANDARD and MANAGED Disks. Including both the OS Disk and the DATA Disks

5 Star
808 times
Add to favorites
Windows Azure
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Managed disks are not being deleted
    5 Posts | Last post September 20, 2019
    • Hi,
      I have ran through the script following all the steps but, the managed disks are not being deleted. Any ideas
    • did you just download it?
      I haven't used the script for so long... I will try to test it out today.
      then can provide an update.
    • are you using managed disks for your data disks or old style disks with vhduri ?
    • okay i found the issue
      i had
                      $DataDisks = @($VM.StorageProfile.DataDisks.Name)
                      $OSDisk = @($VM.StorageProfile.OSDisk.Name)
      Since I was already only grabbing the .Name it was only a string not an disk object.
      ($OSDisk + $DataDisks) | where {$_.Name} | ForEach-Object {
      updated to
      ($OSDisk + $DataDisks) | where {$_} | ForEach-Object {
      Also made one other update
      Write-Verbose -Message "Connected to $($ctx.Context.Subscription.Name)" -Verbose
      Write-Verbose -Message "Connected to $($ctx.Subscription.Name)" -Verbose
      You can just download it again....
    • okay yeah that is back to normal now.
      All fixed.
  • The managed disks was not deleted
    5 Posts | Last post November 21, 2018
    • I ran the script, but the managed disk was not deleted.What could be the reason?
      Remove-AzureRMVMInstanceParallel -ResourceGroup $rg -VMName $role -Wait
      Warning: Deleting VM:[testvm2] from RG:[test]
      Warning: Deleting VM:[testvm2] from RG:[test]
      OperationId : 
      Status      : 
      StartTime   : 
      EndTime     : 
      Error       : 
      Warning: Removing NIC: testvm2554
    • Let me take a look . . . I had to make an update to the script recently to take care of a scenario where there were no data disks. . .
      I will have to test the update thoroughly since I may have missed something with the update. . . if I post an update I will update the title of the script with the month/date.
    • just to confirm did you run the following first ? and did the VM get deleted ? and you are sure the data disks were attached to the vm ?
      Select-AzureRmSubscription -SubscriptionName MSDN 
      Save-AzureRmContext -Path $home\ctx.json -Force 
    • I ran those commands before running "Remove-AzureRMVMInstanceParallel", the vm and nic were deleted, but the os disk and data disk were not deleted, and the data disk had been mounted to the vm.
    • okay, yeah likely the recent code change that I made . . . I'll have to revisit.
  • Not working to me,
    2 Posts | Last post July 19, 2018
    • Just run as follows but nothing happens. Anything missing?
      PS D:\Mydata> .\Remove-AzureRMVMInstanceParallel -ResourceGroup $rg -VMName $vm -Wait
      PS D:\Mydata>
    • The script contains a function that has to be loaded into memory before it is called.
      # load the function
      . .\Remove-AzureRMVMInstanceParallel.ps1
      # save your context as described in the help.
      # call the function
      Remove-AzureRMVMInstanceParallel -ResourceGroup $rg -VMName $vm -Wait
  • The script is trying to remove all the managed disk of a resource group
    2 Posts | Last post December 21, 2017
    • Hi,
      I tried to use this procedure to remove VM with associated NIC and disks. In my context, I only have managed disks. I launched the script with the name of my resource group and the VM but the script tried to remove all the disks in the resource group. The scope was not restricted to the VM i entered in parameter. It seems that this command is returning all the disks in the RG: Get-AzureRmDisk -ResourceGroupName $ResourceGroup -DiskName $_
      Can you help me on that? 
    • The script will delete all VM's, NICS and Disks.
      The items that will be deleted will be the ones that you see returned from running the commands below. So if there is output from the commands below those VM's will be deleted if you execute the function.
      # The resource group where the servers are deployed 
      $rg = 'AZEUS2-MY-APP' 
      # Delete the SQL and the Integration services role servers 
      $role = 'SQL|IS' 
      #Run the following first to confirm which machines/s will be deleted.  
      Get-AzureRMVM -ResourceGroup $rg | Where Name -Match $role