Q: How can I get a full list of every virtual hard disk (VHD) being used by virtual machines (VMs) running in a cluster of Hyper-V hosts?

A: The Windows PowerShell script below extends the code from "List Every VHD Used on a Hyper-V Host," which helps you quickly get a list of every VHD being used by a VM on a Hyper-V host and gets all resource types that are VMs from a cluster.

Note that the code to get the details of the disk is executed on the node currently running the VM.

  1. $VMs = Get-ClusterGroup | ? { $_.GroupType –eq “VirtualMachine” } | Get-VM
  2. Foreach ($VM in $VMs)
  3. {
  4.   $HardDrives = $vm.HardDrives
  5.   Invoke-Command –ComputerName $vm.computername –scriptblock
  6.   {
  7.     Param($HardDrives)
  8.     Foreach ($HardDrive in $HardDrives){$HardDrive.Path | Get-VHD}
  9.   } –Args $HardDrives
  10. }