Using PowerShell to List VHDs Used On a Hyper-V Host

Using PowerShell to List VHDs Used On a Hyper-V Host

Q: How can I quickly get a list of every virtual hard disk (VHD) that's being used by a virtual machine (VM) on a Hyper-V host?

A: The Windows PowerShell script below finds all VMs on the current host, then lists all the VHDs associated with the VMs.

$VMs = Get-VM
Foreach ($VM in $VMs)
{
  $HardDrives = $VM.HardDrives
  Foreach ($HardDrive in $HardDrives)
  {
    $HardDrive.path | Get-VHD
  }
}


 

See also "Using PowerShell to List VHDs In a Hyper-V Cluster."

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