Parallel Delete Azure RM Virtual Machine-NIC-Disks (Updated June 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
(1)
626 times
Add to favorites
Windows Azure
6/21/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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?
      Thanks,
      Regards
      
      Remove-AzureRMVMInstanceParallel -ResourceGroup $rg -VMName $role -Wait
      
      testvm2_OsDisk_1_547e8afa33c74cb1b229d5737e23a6d7
      testvm2_DataDisk_0
      /subscriptions/0b3511c1-xxxx-xxxx-bbfa-6306f9a208fb/resourceGroups/test/providers/Microsoft.Network/networkInterfaces/testvm2554
      
      Warning: Deleting VM:[testvm2] from RG:[test]
      testvm2_OsDisk_1_547e8afa33c74cb1b229d5737e23a6d7
      testvm2_DataDisk_0
      /subscriptions/0b3511c1-xxxx-xxxx-bbfa-6306f9a208fb/resourceGroups/test/providers/Microsoft.Network/networkInterfaces/testvm2554
      
      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 ?
      
      Add-AzureRMAccount 
      Get-AzureRmSubscription 
      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.
      Thanks.
    • 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? 
      Thanks,
      Regards
    • 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