Using PowerShell to List VHDs In a Hyper-V Cluster

Using PowerShell to List VHDs In a Hyper-V Cluster

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.

$VMs = Get-ClusterGroup | ? { $_.GroupType –eq “VirtualMachine” } | Get-VM
Foreach ($VM in $VMs)
{
  $HardDrives = $vm.HardDrives
  Invoke-Command –ComputerName $vm.computername –scriptblock 
  {
    Param($HardDrives)
    Foreach ($HardDrive in $HardDrives){$HardDrive.Path | Get-VHD}
  } –Args $HardDrives
}

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish