MVP Logo

Thomas LeeThomas Lee is a UK IT Pro, with over 40 year’s experience in the IT field. He’s presently a PowerShell MCP and is very busy doing writing, consulting and training around some of the key Microsoft technologies including PowerShell, Lync and Windows Server/client. In his spare time, he lives in a small cottage with wife, daughter, a nice wine cellar and a large collection of Grateful Dead live recordings.

Introduction

Hyper-V is Microsoft’s virtualization solution. It was first released with Server 2008 and improved with Server 2008 R2. The latest version comes with both Server 2012 and Windows 8. The inclusion of Hyper-V in both the client and server version is a great step forward and for me, at least, it means the end of 3rd party virtualization products I needed to use in the past.

PowerShell is Microsoft’s strategic task automation platform which has been significantly upgraded to Version 3. PowerShell Version 3 is included in all versions of Windows Server 2012, and Windows 8. A downloadable version will also be made available at some point for Windows 7, Server 2008 and Server 2008 R2. Beta versions of PowerShell v3 are available in the mean time for down-level operating systems, but you’ll want the full V3 once that’s available.

The cool thing, or should I say one of the many cool things, about Hyper-V and Server 2012 is that you can manage Hyper-V using PowerShell. There is a new Hyper-V module that ships, in the box!, for both Windows 8 and Server 2012. However, the module and the Hyper-V features are neither installed by default. On Windows 8, you need to bring up Control Panel, click Programs, then click Turn Windows feature on or off and then select Hyper-V. For Windows Server 2012, you can use Server Manager GUI, or the Server Manager PowerShell Module and use the Add-Windows Feature cmdlet. Personally, I find the latter quicker in most cases.

On a Windows 8 and Server 2012 systems, you can install the Hyper-V software itself and the management tools (i.e. the PowerShell module) separately. This enables you to manage a set of VMs remotely.

The Hyper-V module

The Hyper-V module contains a huge number of cmdlets, 164 in total. That’s a lot of cmdlets – but there’s a lot to manage in Hyper-V! The first thing to remember about this module – you need to be in an elevated prompt in order for the cmdlets to work. I got a bit of a fright when I ran the Get-VM cmdlet on my windows 8 box (which had a number of VMs) and had it return nothing (not even an error).

The Hyper-V module allows you to manage all aspects of the virtualization package. You can manage VMs, VHDs, network witches, network adapters and other fundamental objects. You can also manage all aspects of running Hyper-V in a clustered environment with SANs, ,etc.

To create a VM, using the Hyper-V module, you just use the New-VM cmdlet, as shown here:

clip_image002

As you can see from this screen shot, there are just three cmdlets to run in order to create a simple VM: New-VM (to create a new VM and VHD virtual disk drive), Set-VmDvdDrive to add a DVD into the VM (in this case the Server 2012 installation DVD), then Start-VM to start up the virtual machine. If you then run the Virtual Machine Connection applet, you see the following

clip_image004

Now if I’d been clever, I could have done a whole lot more, including injecting a floppy disk into the VM containing the unattend.xml file that would automagically configure the installation, in this case, of Windows Server 2012.

Once the server has been started, I can go back to PowerShell and view the VM using the Get-VM cmdlet, as follows:

clip_image006

This screen shot shows the Get-VM and some of the properties of the newly created VM (there are a total of 54 separate properties you can make use of!

Using the Hyper-V Module

I’ve been using the Hyper-V module throughout the Server 2012 beta period to create and manage VMs. Most of the VMs I’ve created are server VMs, but I’ve also created several Windows 8 Beta VMs. I can’t be bothered to create an unattend.xml file, so I’ve been just creating a basic VM as you see it, using the VMC applet to just ‘next-next-next’ through the installation. Once I have a basic VM created, I can run a Configure-VM.ps1 script that configures the system (changes hostname, updates the IP configuration etc). I have further scripts that do further configuration. I can now setup a 5vm ‘farm’ including a DC/DNS/CA system, a SQL server system, an Exchange server plus a couple of additional basic servers all in around half an hour.

Hyper-V module – good but not perfect

I’ve found the Hyper-V module great for most things, but there are a few omissions. For example, I cannot create a virtual floppy disk on a host machine and write directly to it (then remove it from the host and add it to the vm. This makes unattended setups harder than I’d like.

There are a lot of cmdlets in the module and they operate at a fairly basic level. I found it took a few hours of playing around to find all the things I needed. But having said that, it isn’t that difficult – I found myself writing scripts as I went along and by the end of a few days playing, I had a wealth of provisioning scripts that will keep me in good stead.

Learning PowerShell v3

For many of you, PowerShell is still a bit of an unknown quantity. If so, consider coming on the Windows PowerShell PowerCamp weekend training course I’m running over the weekend of October 27/28. For fuller details, see my blog at http://tfl09.blogspot.com. The PowerCamp, which will be held in Microsoft’s Cardinal Place offices, is intended to take you through the basics of PowerShell V3 and I plan to spend some time looking at the Hyper-V module.

PowerShell and Hyper-V Module summary

While not perfect, the module is a lot faster, for me, than using the GUI, especially given the number of VMs I regularly create. For some users, the Hyper-V module might be a good alternative to using a VM management tool such as System Center Virtual Machine Manager. You could write all the scripts to create/manage VMs, do VM Checkout, etc!

All in all, the combination of Hyper-V, Windows 8/Server2012 is a great set of virtualization and virtualization management software.