Overheard at my recent IT Pro events on Windows Server 2012 Hyper-V ...
"After I've setup a number of VM's, it's easy to forget which virtual hard disk files are used by which VM's. How can I get a list of ALL virtual hard disks for ALL virtual machines on a Hyper-V Host?"
In this article, I'll step through the process of generating an inventory of all virtual hard disks across all VM's on a Hyper-V Host running Windows Server 2012 or our completely FREE Hyper-V Server 2012 ...
While the GUI-based Hyper-V Manager tool gives a view of VM settings on a VM-by-VM basis, the Hyper-V PowerShell module in Windows Server 2012 provides the capabilities to see configuration settings across all VM's. It all starts with the Get-VM PowerShell cmdlet, which provides us with a list of the currently provisioned VM's on a Hyper-V Host ...
Get-VM returns a collection of PowerShell objects for each and every VM that is currently provisioned on a Hyper-V host. To see a specific set of configuration settings, such as Virtual Hard Disks, we can pipe the output of Get-VM to the appropriate PowerShell cmdlet related to a particular set of configuration settings. In this case, we'll pipe Get-VM's output to the Get-VMHardDiskDrive PowerShell cmdlet ...
If you'd like a scrollable, sortable GUI view of this output, simply pipe the above command line to the Out-GridView Powershell cmdlet, and you'll receive a GUI display of the output as follows:
Alternatively, you could also pipe the command line output to the Export-Csv PowerShell cmdlet to generate a CSV text file with all of the details. This could be useful if you want to work with these VHD files within another script.
In addition to generating a list of all virtual hard disks across all VM's, you can also leverage the same process as listed above to generate many other lists of configuration items just by substituting the appropriate PowerShell cmdlet in place of Get-VMHardDiskDrive. Take a peek at the Get-VM* cmdlets on the Hyper-V Cmdlets page to get a full list of the information that you can leverage in this manner. For example, to pull all virtual networks to which each VM is connected, you can use the Get-VMNetworkAdapter in the following PowerShell cmdline:
The best way to learn new technology is to setup your own lab environment and step through the new capabilities for yourself! Our FREE "Early Experts" Challenge study group is a great way to jumpstart your learning in this manner. "Early Experts" incorporates video-based lectures, structured study materials and hands-on labs that you build out in your own environment or in our Windows Azure cloud for FREE!
Do you have information that you've been trying to pull out of Windows Server 2012 Hyper-V for better management of your VM's? Leave your challenge below in the Comments and we can explore ways in which you can address your VM information needs!
Be sure to check out these additional resources:
Keith Mayer is a Senior Technical Architect at Microsoft, focused on helping ISV partners leverage the Azure cloud platform. Keith has over 20 years of experience as a technical leader of complex IT projects, in diverse roles, such as Network Engineer, IT Manager, Technical Instructor and Consultant. He has consulted and trained thousands of customers and partners worldwide on design of enterprise technology solutions.
Keith is currently certified on several Microsoft technologies, including Azure, Private Cloud, System Center, Hyper-V, Windows, Windows Server, SharePoint, SQL Server and Exchange. He also holds other industry certifications from VMware, IBM, Cisco, Citrix, HP, CheckPoint, CompTIA and Interwoven.
You can contact Keith online at http://aka.ms/AskKeith.