Overheard at a recent IT Camp event …
I’ve been virtualizing more and more VMs on my Windows Server 2012 Hyper-V hosts lately and I’ve got lots of virtual hard disks ( VHDs ) across all my VMs.
It’s been working great, but … Is there an easy way to list all VHDs that I’m using across all hosts and VMs?
In this article, I’ll show the process for leveraging PowerShell 3.0 and the Hyper-V PowerShell module in Windows Server 2012 and our completely FREE Hyper-V Server 2012 to easily list all VHDs that are in use across all VMs and Hyper-V hosts … in just ONE line of PowerShell code!
PowerShell to the rescue!
Great question! The Hyper-V Manager GUI tool that’s included with Windows Server 2012 is organized on a VM-by-VM basis. It’s great for working with VMs across multiple host servers, but normally you’d need to drill into the properties of each VM via the GUI to expose the associated virtual hard disks.
However, with just a bit of PowerShell code … we can easily produce a report that enumerates all virtual hard disks across all virtual machines and Hyper-V hosts. Here’s the PowerShell code snippet:
Get-VM –ComputerName HOST1, HOST2, HOST3 |
Select-Object -Property VMName, VMId, ComputerName,
ControllerLocation, Path |
Sort-Object -Property VMName |
Out-GridView -Title “Virtual Disks”
Note that the snippet above is a single line of PowerShell code – I’ve just wrapped it onto multiple lines for readability.
After running this snippet from within the PowerShell ISE, you’ll be presented with a nicely formatted report of all VHDs, organized by VM and Hyper-V Host, as follows:
Want more? Become a Virtualization Expert in 20 Days!
This month, my fellow Technical Evangelists and I are writing a new blog article series, titled Become a Virtualization Expert in 20 Days! Each day we’ll be releasing a new article that focuses on a different area of virtualization as it relates to compute, storage and/or networking. Be sure to catch the whole series at:
After you’re done reading the series, if you’d like to learn more and begin preparing for MCSA certification on Windows Server 2012, join our FREE Windows Server 2012 “Early Experts” online study group for IT Pros at:
Have a useful PowerShell snippet you want to share?
Do you have a unique or useful PowerShell snippet that you’d like to share? Feel free to share your snippets in the comments below!