Using PowerShell to List VHDs In a Hyper-V Cluster

List every VHD used in a Hyper-V cluster by using Windows PowerShell.

John Savill

September 4, 2013

1 Min Read
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-VMForeach ($VM in $VMs){  $HardDrives = $vm.HardDrives  Invoke-Command –ComputerName $vm.computername –scriptblock   {    Param($HardDrives)    Foreach ($HardDrive in $HardDrives){$HardDrive.Path | Get-VHD}  } –Args $HardDrives}

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like