The Hyper-V PowerPack for PowerGUI that I published last month is one of my favorite PowerPacks so far. It’s a great example of how you can take a task that is pretty complicated for someone who doesn’t program for a living (like using PowerShell to manage Hyper-V via WMI), simplify it with rich PowerShell functions that look and feel like cmdlets, and then build a user interface on top those functions to perform management and automation tasks. Since all of the PowerShell script behind the PowerPack is freely available through the PowerGUI Admin Console, using a PowerPack like the Hyper-V PowerPack is a great way to learn PowerShell because it allows you to get familiar with how specific administrative tasks translate into PowerShell scripts that you can then use for automation, provisioning, scheduled tasks, etc.
The scripts powering the Hyper-V PowerPack are particularly interesting because there are no cmdlets available yet to manage Hyper-V unless you use Microsoft System Center Virtual Machine Manager 2008. The prescribed way to manage Hyper-V via script with the release of Windows Server 2008 is WMI. Since working with WMI directly is not much fun after you have become spoiled with the ease-of-use you get with PowerShell cmdlets, not to mention quite difficult, I have included a lot of useful functions (over 30 of them so far) that wrap the WMI management code inside of a cmdlet-like experience complete with support for pipelining so that you can write scripts to work with your Hyper-V servers much more easily. Here’s a complete list of the functions that are included in the current revision of the Hyper-V PowerPack:
Job Management
Get-HyperVJob
Wait-HyperVJob
Server Configuration
Get-HyperVServerSettings
Set-HyperVServerSettings
Service Management
Get-HyperVService
Physical Network Adapter Management
Get-HyperVPhysicalNIC
Set-HyperVPhysicalNIC
Virtual Network Management
Get-HyperVVirtualNetwork
New-HyperVVirtualNetwork
Remove-HyperVVirtualNetwork
Rename-HyperVVirtualNetwork
Set-HyperVVirtualNetwork
Virtual Machine Management
Checkpoint-HyperVVirtualMachine
Export-HyperVVirtualMachine
Get-HyperVVirtualMachine
Import-HyperVVirtualMachine
New-HyperVVirtualMachine
Remove-HyperVVirtualMachine
Rename-HyperVVirtualMachine
Restore-HyperVVirtualMachine
Set-HyperVVirtualMachine
Virtual Network Adapter Management
Add-HyperVVirtualNIC
Get-HyperVVirtualNIC
Remove-HyperVVirtualNIC
Set-HyperVVirtualNIC
Virtual Ide Drive Management
Add-HyperVVirtualIdeDrive
Virtual Scsi Drive Management
Add-HyperVVirtualScsiDrive
Snapshot Management
Get-HyperVSnapshot
Set-HyperVSnapshot
Remove-HyperVSnapshot
Rename-HyperVSnapshot
Update-HyperVSnapshot
Virtual Hard Disk Management
Get-HyperVVirtualHardDisk
New-HyperVVirtualHardDisk
These functions do not provide comprehensive coverage of all Hyper-V features and there are many more that I plan to add in a future update, but it’s well on it’s way to becoming a comprehensive set of functions. If you are looking for specific functionality that doesn’t appear to be available through these functions, I encourage you to take a look at the methods on the rich objects that are output by these functions. There is a whole lot more functionality available than you might think! I just haven’t had time to expose all of the method-based functionality as cmdlet-like functions yet.
To use these functions in your own scripts you simply have to copy them out of the Hyper-V PowerPack. Be sure to keep an eye on dependencies and make sure you get all the functions you need. Most of the PowerPacks I’ve been working on lately come with useful functions like this, for the explicit reason that I want people to be able to use them inside and outside of PowerGUI. I’ll blog about them as time permits, but until I make time for that I wanted to at least make you aware that they are there as a resource and as a learning tool.
If you want to write PowerShell scripts to manage your Hyper-V servers, doing yourself a favor to take a look at the Hyper-V PowerPack and the functions that it contains. They might go a long way to helping you get your work done faster and more easily, either by using the functions themselves in your scripts or by looking at the PowerShell code behind the functions and learning how to get WMI to do what you want to do.
Kirk out.
Share this post: | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
[…] In case you haven’t had a chance to see some of the functionality that this PowerPack provides you with, I’m including a few screenshots below to give you a quick preview. Or, if you want to see the list of custom functions that drive the functionality in this PowerPack, read my blog post titled, “Use PowerPacks to Learn PowerShell“. […]
Thanks Kirk,
I’ve been looking for somthing like this to be able to control my VM in Hyper-V for a series of courses I’m planing on….
Happy holidays