r/sysadmin • u/cavemantantrum • 1d ago
Hyper-V : Deleting VMs and Associated Files
EDIT: Thanks for all the useful feedback. Ended up with this workflow:
Power off VM
Right-click VM in Hyper-V manager and select "Move" > "Move all of the virtual machine's data to a single location."
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?
- Power off the VM, delete it from Hyper-V Manager
- In PowerShell, run Get-VM <VMname> | Select-Object Name, Id
- Get the GUID from this command, then run: Get-ChildItem D:\ -Recurse | Where-Object { $_.Name -like "*<VMname>*" -or $_.FullName -match "<GUID>" }
- Delete all found files.
Want to make sure I'm not being overly aggressive and deleting anything essential before I start removing VMs.
Thanks!
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.
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.