Completely remove Hyper-V Virtual Machines

Device management

Yes, I know, why not use Hyper-V console remove Virtual Machines?

Thanks for Jokelainen Jouni gave me this idea about create this script!

So as you know, when delete Virtual Machines from Hyper-V console, it left all the checkpoint hard disks and virtual hardisks behin. In a case, if you have lots of Hyper-V host, lots of Virtual Machines, it is pain in the ass to clean them up.

So I came up this simple powershell script. This script can be use only locally in a Hyper-V host, not remotely. And it need to be run as Administrator.
Inside the script, has a funtion call “Remove-MyLabVM”, you can just use the funtion if you don’t want use the powershell menu I made.

Β 

Just for fun, I also make a “Remove Virtual Machine” tool.

When use it locally, it need to be run as admin rights, and do not required input username and password.
When use it remotely, it can be run as normal user right, and it is need to input username and password that has admin rights for the remote Hyper-V host.
When use it remotely, it also required your firewall and winrm are configured as allowed, because it needs to run powershell remotely to another computer.

You can download it from GitHub: https://github.com/sandytsang/Hyper-V/tree/main/Remove%20Hyper-V%20VMs

12 thoughts on “Completely remove Hyper-V Virtual Machines

  1. Thanks Sandy..i used to have billions of virtual machine leftovers from different kind of tests. Its pain to remove them because when created in a hurry, the virtual hard drives are not necessarily in same place with other machine files. Removing them manually is pain in the butt ……but not anymore πŸ˜€ πŸ˜€

  2. While this is kinda old, do you still have it published somewhere, see the link to TechNet is dead. Just heard about it via a Tweet and wanted to check it out for my lab where I am constantly creating and deleting VMs

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.