Hyper-V On-The-Go – Enabling the Lab Engine

Boldly Going – The Shakedown Cruise

In an earlier blog I laid out some basics needed to build your own portable lab. I focused on the hardware needed and the considerations you need to keep in mind to ensure a successful effort. The hardware, however, is merely a tool (albeit a useful one) and needs a proper configuration to make it produce the results you are looking to achieve. In other words, if you don’t feed that dog, it won’t warp!

Dilithium Schmilithium!

The next step in our bold voyage (See? A theme!) of undiscovered labbing is to enable Hyper-V. For this discussion I am going to assume it is disabled. I am going to demostrate a couple of different ways to do this by using the GUI and then programatically using PowerShell. So let’s get on with the mission.

Grinding the GUI

Installing Hyper-V in the GUI is pretty straightforward, we’ll find it in the Control Panel. Type ‘control’ in the searchbar and click on its icon when it appears in the list:

Once Control Panel is open, start typing ‘feature’ in the search window and then select ‘Turn Windows Features On or Off’

In the ‘Features’ window, check the checkbox next to Hyper-V, expand the selection and make sure that all the sub-checkboxes are also checked. Click on ‘OK’ to finish the install and close out of Control Panel.

At this point Hyper-V is enabled and ready to go. A reboot may be required depending on the Operating System (OS) you’re running.

Warping with the Shell

The GUI is great and as you’ve seen, an easy interface to work with but what if you crave a little automation to open up other options? Well then PowerShell may be a better answer for you. The advantages of using Powershell are many; faster installs, consistent installs across machines and remote installation across networked machines just to name a few.

Now I want to point out that I will be demonstrating two versions of the same code. This is due to the differences between how features are installed on a client OS versus a Server OS. Whichever OS you’re running on your host machine, the following code examples will allow you to enable Hyper-V.

Before proceeding, be sure to open your PowerShell session in an elevated context as administrative right are required to add this feature to the machine.

On a client OS you will need to have the DISM module installed in order to proceed. to do this run the following:

Import-Module DISM

Your results should resemble this:

The server OS requires the Server Manager module to be installed, to do this run the following:

Import-Module ServerManager

Your results should resemble this:

With the necessary management modules in place we are now ready to enable Hyper-V. Depending on your OS type run one of the follow snippets:
Client OS Code:

 Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All 
Server OS Code:
 Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart 

NOTE: The client OS will prompt for a reboot, there is no switch to bypass this.
Below are examples of the code running on a client and a server:

Installing on a Client OS
Installing on a server OS, the reboot is automatic
Engineer’s Formula for an Awesome Reputation (Estimated Time x 4 = Godlike Rep)

Montgomery Scott said it himself, “Never give them a real estimate of a repair time lad! Multiply by four then deliver on your real estimate! They’ll think you’re a bloody miracle worker!”. There is no way we’ll get those kind of results, so we’ll just settle on it being a little quicker and most importantly, successful. To do that, our next step is to verify that Hyper-V is actually enabled.

Log in to the host and re-run the PowerShell console in an elevated context. Run the Get-Feature command for the OS you are using to list the relevant features as demonstrated below:

Using Get-WindowsOptionalFeature to verify Hyper-V (Client OS)
Using Get-WindowsFeature to verify Hyper-V (Server OS)

Stardate Undecided (…the continuing missions…)

The portable lab is a gateway to a new universe. It gives you a local toolkit to build out almost any lab scenario you may need (within the restrictions of your hardware). It will also prepare you for working with Hyper-V Servers and System Center Virtual Machine Manager (SCVMM). SCVVM is designed for managing large virtual environments but if you have the hardware to support it, it is well worth the effort of experimenting with it. The contrasts between it and VMWare ESXi are interesting and well worth exploring.

Understanding the intricacies of virtualization is a major benefit of exploring lab scenarios in Hyper-V. The knowledge you gain will also help you to learn and better understand Azure and its various deployment models. The basic foundations for both are similar.

For those who would like to further explore lab automation I again recommend Jaromir Kaspar’s website. There are several hydration (rapid lab deployment) kits and projects out there and there are two I think are worth investigating. The two specifically are:

  • PSAutoLab – A GitHub project created by Jason Helmick and Melissa Janusko. It is a powerful hydration tool.
  • AutomatedLab – Enables you to setup test and lab environments on Hyper-V or Azure with multiple products or just a single VM in a very short time.

I hope you will enjoy playing with and learning in your lab journeys. I will be posting more fast-fix and simple-trick blogs in the ‘Boldly Going’ series. I hope they will help to tweak your lab experiences and work around any potential gotchas. Until then, “Lab long and prosper“.