PowerShell Not your Father’s Command Line Part 20 of 31: Hanging With Hyper-V

imageWhen Windows Server 2008 R2 was initially released there was no Hyper-V module for PowerShell to work directly with the Hyper-V role. You could work with Hyper-V via the Windows Management Instrumentation (WMI). While WMI provides an invaluable component to your PowerShell sessions, it comes with a layer of compatibility. Sarah will tackle WMI in an upcoming post in the series.  To give you an example of just the basics of navigating the WMI name space for Hyper-V you see all the list of all the objects to work with in WMI for Hyper-V:

Get-WMIObject –namespace “root\virtualization” –list

While working WMI can prove to be effective, it is not the easiest way, as you may have realized when you saw the WMI name space.

More importantly the PowerShell community agreed. They designed and built a Hyper-V management library specifically to access the Hyper-V components.  The management library provides over 80 functions in the library, some of these are worker functions which are not expected to be called directly, but when combined with cmdlets you can work easily with Hyper-V in PowerShell.  When you work with the library, a majority of the information available from Hyper-V is only available if PowerShell is running with Elevated privilege.  To get the Hyper-V Management Library you can find download it from Codeplex here: PowerShell Management Library for Hyper-V  

The library comes in a zip file.  After you have downloaded the file you will need to unblock the file so you can run the installation of the file successfully.  Right click on the file you have downloaded and on the general tab click on unblock, then you can run work with the Hyper-V module.   Run install.cmd as an administrator, and it will install the Hyper-V module, and in your PowerShell sessions you can run Import-Module HyperV to work with the cmdlets. 

You have several cmdlets to work with all aspects of Hyper from Connecting to a VM, discovering and manipulating machine states (with cmdlets like Get-VMState) , backing up, exporting and snapshotting VMs (with cmdlets like Export-VM) ,adding and removing VMs, configuring motherboard settings (with cmdlets like New-VM), modify Disk controllers, drives and disk images (wth cmdlets like Get-VMDiskController), Work with Network Interface Cards, and working directly with the VHD files.  The management library really does offer a lot of easy and powerful cmdlets. You can get a full list of the cmdlets with Get-Command –module HyperV.  However this is one cmdlet to rule them all and it is the following cmdlet:



As you can see from the above picture you have a PowerShell menu that will allow you to mange Hyper-V easily.   provides a great tool for Windows Server 2008 R2 core installations as well.  If you work with Hyper-V and wanted to manage it with PowerShell, you will definitely work with this library.

Thanks for reading and if you missed any of the previous posts you can find a master list of series postings located here: PowerShell Not Your Father's Command Line: 31 Days of PowerShell or on Sarah’s blog here: PowerShell Not Your Father's Command Line: 31 Days of PowerShell. Lastly Sarah and I want to hear from you email either of us with your comments or suggestions for future postings let us know, we look forward to hearing from you. Have a great day!

Comments (0)

Skip to main content