Partager via


Enabling Hyper-V Role Successfully via Operating System Deployment Task Sequence

During a ask-the-experts at Microsoft Management Summit (MMS) 2011 in Las Vegas, a customer asked a question of how to utilize Microsoft Deployment Toolkit (MDT) 2010 Update 1 to install Windows Server 2008/R2 and enable the Hyper-V role.  The customer had tried several things but to no avail as the customer was using ConfigMgr’s Operating System Deployment (OSD) feature and this wasn’t working.  In today’s post, I thought I would share how to easily do this.

First things First – What doesn’t Work

The first thing I wanted to share is that using traditional methods to install Hyper-V role such as using ServerManagerCMD, PowerShell, or Package Manager (OCSetup) doesn’t work.  If you attempt to add a step in your task sequence to open a Command Prompt and execute one of the following commands you will determine quickly that it doesn’t work.

Installing Hyper-V Role using ServerManagerCMD.exe

This deprecated tool still works and is an easy-to-use tool to query, install, or uninstall a role or feature such as Hyper-V.  To install Hyper-V using this tool, execute the following command -

 servermanagercmd.exe -install Hyper-V

To determine if it is already installed, you can use ServerManagerCMD.exe –query -

image

Installing Hyper-V Role using PowerShell on R2

On R2, you can use PowerShell that is enabled by default for the Operating System.  To install Hyper-V role using PowerShell, you can use the following -

First: Import Server Manager Module:

 Import-Module servermanager

Second: Install Hyper-V:

 Add-WindowsFeature Hyper-V

Installing Hyper-V Role using OCSetup

You can also use Package Manager (OCSetup) to install the Hyper-V role.  To do this, use the following command-line:

 Start /w ocsetup Microsoft-Hyper-V

Doesn’t Work – What else is left?

As you will find out quickly, this doesn’t work when you utilize a task sequence.  I’m not going to claim to be an expert on exactly why this fails within a task sequence but I can tell you what works 100 percent of the time. 

You can use the Windows Edition-Servicing tool called DISM.exe to add the Hyper-V role and this will work.  To effectively do this, do the following:

  • Add a  command-line task sequence step that executes the following command:
 cmd /c Dism.exe /image:%OSDTargetDrive%\ /Enable-Feature /FeatureName:Microsoft-Hyper-V /LogPath:%_SMSTSLogPath%\Hyper-V.log
  • Add a second command-line task sequence step that executes the following command:
 cmd /c Dism.exe /image:%OSDTargetDrive%\ /Enable-Feature /FeatureName:Microsoft-Hyper-V-Management-Clients /LogPath:%_SMSTSLogPath%\Hyper-Vclient.log

NOTE: These commands should be executed post-operating system installation.

In short, what we are doing here is calling Dism.exe and pointing it to the image path (WIM) that is for the targeted OS installation drive.  This will enable the Hyper-V role.  Beyond this, we set the path for the logs as well as installed the Hyper-V management client.

Putting it All Together

In today’s quick, brief post, I wanted to share some details that we had to learn as we were building the ConfigMgr P2V Migration Toolkit as one of the key features it provides is the ability to build stand-alone media that will create a P2V image of  your existing machine, copy it to a USB/Network location, and then install Windows Server 2008 using ConfigMgr’s Task Sequence engine.  As part of this solution, we had to execute the installation of Hyper-V and during our testing we determined that using any of the various options listed above in the first section doesn’t work – it fails every time.

I had this customer ask this question (unrelated to P2V) but I realized that this wasn’t clear in a lot of places so I felt this might be a great time to share this little tad bit of information!

Enjoy!

Thanks,

-Chris