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:
Physical Network Adapter Management
Virtual Network Management
Virtual Machine Management
Virtual Network Adapter Management
Virtual Ide Drive Management
Virtual Scsi Drive Management
Virtual Hard Disk Management
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.
|Share this post:|
2 thoughts on “Use PowerPacks to Learn PowerShell”
[…] 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“. […]
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….