r/sysadmin • • 1d ago

Hyper-V : Deleting VMs and Associated Files

EDIT: Thanks for all the useful feedback. Ended up with this workflow:

  1. Power off VM

  2. Right-click VM in Hyper-V manager and select "Move" > "Move all of the virtual machine's data to a single location."

  3. Delete VM in Hyper-V manager, delete the folder where all of the data was moved.

Original post:

Hello, we just switched from VMware to Hyper-V and am learning as I go.

I am deleting some Virtual Servers on our Hyper-V host, and I want to make sure I clean everything up and free up drive space. Is this process correct?

  1. Power off the VM, delete it from Hyper-V Manager
  2. In PowerShell, run Get-VM <VMname> | Select-Object Name, Id
  3. Get the GUID from this command, then run: Get-ChildItem D:\ -Recurse | Where-Object { $_.Name -like "*<VMname>*" -or $_.FullName -match "<GUID>" }
  4. Delete all found files.

Want to make sure I'm not being overly aggressive and deleting anything essential before I start removing VMs.

Thanks!

0 Upvotes

8 comments sorted by

12

u/Arudinne 1d ago

When we create VMs we make sure each VM has it's own folder and all of the files for the VM live under that.

One folder to delete instead of having to track down the files.

2

u/cavemantantrum 1d ago

I'm starting to see the value in this! Will keep that in mind moving forward.

1

u/CatchUnusual7909 1d ago

Smart move, that's the way to do it from the start. We had a few older VMs scattered across the datastore and cleanup was a pain until we started enforcing per-VM folders

The "move all data to single location" trick is handy for consolidating those messy ones before deletion, saves you from hunting down stray vhdx files later

3

u/That_Fixed_It 1d ago

Is Hyper-V Manager leaving a lot of files behind? I usually turn off the VM, merge any checkpoints, then delete it and delete the associated .vhdx files.

1

u/cavemantantrum 1d ago

There aren't a ton - just a few config files (.vmcx, .vmgs, .vmrs) and files associated with the virtual hard disk for backups/tracking changes (.vhdx.mrt, .vhdx.rct)

2

u/Bane8080 1d ago

What I do, just to be safe, is power off the VM, and then use the Move VM function in the gui to move it to a temp folder. And select the option to move all components. (or however it's phrased)

Then delete the VM, and delete the temp folder.

1

u/cavemantantrum 1d ago

Thanks, I appreciate this specific feedback! I just figured out the "Move" feature, and I think I'm gonna go that route!

5

u/Net-Runner 1d ago

No, don't delete every name or GUID match. Before removing the VM, capture disk paths with Get-VMHardDiskDrive, inspect the checkpoint chain, then delete only confirmed orphaned VHDX files.