We are using Hyper-V R2 as a platform for virtualizing development and testing environment.
After month of use, with creating / deletion of many virtual machine, the vhd store is filled with a lot of vhd and avhd files. Some of them are drives of delete virtual computers.
How can I clean up the virtual drive folder ?
Is there any command line (PowerShell?) than can enumerate all virtual computers' disk binding (so I can remove all except this list) ?
[Edit] A bit of progress
I can list all xml file for VM definitions and analyse the controller sections :
<controller0> <drive0> <pathname type="string">V:\Hyper-V\Virtual Hard Disks\my_computer_7679176A-F7AE-4D40-AC28-67FFDE7E2FEB.avhd</pathname> <type type="string">VHD</type> </drive0> <drive1> <pathname type="string">V:\Hyper-V\Virtual Hard Disks\my_computer_60892A6B-6AB4-44D7-8F08-509BF0E70A05.avhd</pathname> <type type="string">VHD</type> </drive1> </controller0>
However, as the computer can have snapshots, it only enumerates attached disks, and not their parents disks, which are also required.