Install And Configure Hyper-V On Windows Server 2012 R2 With PowerShell. Sure, you can use a GUI to click-click-click your way through the installation and configuration of Hyper-V on Windows Server 2012 R2. Provides a visual reference for understanding key Hyper-V technologies in Windows Server 2012 R2 and focuses on Generation 2 virtual machines, Hyper-V with virtual hard disk sharing, online virtual hard disk resizing, storage quality-of-service, enhanced session mode, live migration, Hyper-V failover clustering, and upgrading your private cloud.
- Install Hyper-v On Windows Server 2012 R2 Server
- Enable Hyper V Role In Windows Server 2012 R2
- Enable Hyper V On Windows Server 2012 R2
I/ Introduction
In this blog post I will go through the steps to create a portable Hyper-V server. We will prepare a USB drive to store the Server Operating System so that we can boot this USB up from a random server hardware should we need a Hypervisor urgently.
As you know, Hyper-V Server 2012 R2 is a free Hypervisor provided by Microsoft. It is a standalone server with only the Hyper-V role on it. Although it is free, it has all the bells and whistles that the Hyper-V server role in Windows Server 2012 R2 has.
II/ Preparation
In this lab, we will need three things:
- Hyper-V Server 2012 R2. Download this file: 9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVERHYPERCORE_EN-US-IRM_SHV_X64FRE_EN-US_DV5.ISO from: http://www.microsoft.com/en-us/evalcenter/evaluate-hyper-v-server-2012-r2
- Windows AIK for Windows 7 downloaded here: http://www.microsoft.com/en-ca/download/confirmation.aspx?id=5753 (the file you download will be KB3AIK_EN.ISO).
- Windows 7 Workstation (in this post I used Windows 10 Technical Preview Workstation).
III/ Step By Step Instructions
Step 1: Installing .NET and Windows AIK
In the Control Panel, click Programs and Features; turn on the .NET Framework 3.5. This will include .NET 2.0 and 3.0. .NET 2.0 is a prerequisite of Windows AIK setup.
The installation of .NET Framework 3.5 requires a reboot.
After rebooting, we need to install Windows AIK for Windows 7. Mount the KB3AIK_EN.ISO file. Run the StartCD.exe file.
Install Hyper-v On Windows Server 2012 R2 Server
Choose Windows AIK Setup.
Click I Agree to accept the license.
Note the installation Path and click Next.
Click Next.
Click Close when done.
Step 2: Copy the Install.WIM file.
We need to copy the INSTALL.WIM file from DVD Sources of the Hyper-V Server 2012 R2 to a temporary location, for example, C:Tmp.
Copy this file:
Paste it in C:Tmp (you have to create the Tmp folder first).
Ensure that the file is pasted correctly.
Step 3: Create a VHD using Diskpart and also show the VHD Drive.
Change the directory to C: (Root directory) and then create a temporary directory called HVBOOT to store boot files for Hyper-V.
Enable Hyper V Role In Windows Server 2012 R2
Run diskpart to create a VHD file; at the command prompt type:
diskpart
Issue the following command to create a VHD file with volume of 6GB and store that VHD file under C:HVBOOT.
create vdisk file=C:HVbootHYPERV.VHD maximum=6000 type=fixed
Now, select that virtual disk and then create a partition and attach the VHD file we just created, we will it as V: drive (V: stands for Virtual – but it does not matter).
select vdisk file=c:hvbootHYPERV.VHD
attach vdisk
create partition primary
assign letter V:
Now format the drive
format quick fs=ntfs label=MYHYPERV
Note that now the new 6GB drive shows up under the Computer tree. This drive is the Virtual Disk that we created.
Type exit to quit diskpart
At this point, we should have a V: drive showing up which is a virtual disk with volume of 6GB. We will now insert the Hyper-V image (Install.WIM) into the VHD that we created and then detach the HYPERV (V:) drive. We cannot simply use copy/paste to insert the Hyper-V image into the VHD. Rather, we will use the ImageX utility inside Windows AIK tools to do that.
Change to this directory:
cd “Program FilesWindows AIKToolsx86″
Type the following command to apply the Hyper-V install image (called Install.Wim that you copied to C:Tmp earlier) to the V: drive.
ImageX /Apply C:TmpInstall.WIM 1 V:
Ensure that we get 100% success.
Now we will use diskpart to unmount the V: drive. Type the following four commands:
diskpart
DISKPART> select vdisk file=c:HVBOOTHYPERV.VHD
DISKPART> detach vdisk
DISKPART> exit
Step 5: Insert USB key, format the USB drive and insert the VHD file to it
Insert a USB drive and use diskpart to determine the disk number before formatting.
diskpart
list disk
In my case, it shows the USB as disk 4.
Enable Hyper V On Windows Server 2012 R2
We are going to select the disk, create a partition, set the partition to be active, format this USB drive with NTFS partition and assign drive letter Z: to it.
select disk 4
clean
create partition primary
select partition 1
active
format quick fs=ntfs
assign letter=Z
exit
After all of the above commands, we will have an empty USB drive (Z:)
Now we are going to copy the VHD file (C:HVBOOTHYPERV.VHD) to the USB drive (Z:). Paste it to the USB key.
Step 6: Create MBR (Master Boot Record) and copy all the boot files to the USB.
For this task we will use the BOOTSECT tool (in the Windows AIK) to create MBR for the USB. Depending on the server architecture, change directory to:
CD ”C:Program FilesWindows AIKToolsPETools x86”
Type the following line to create MBR for the USB (Z: is the USB drive):
bootsect /nt60 Z: /force /mbr
Now, attach VHD again to create BCDBOOT for the next step.
Diskpart
Select vdisk file=Z:HyperV.vhd
Attach vdisk
Exit
Copy the system files from the Hyper-V’s Windows directory (which is the V: drive at this point) into the USB (Z:) drive.
bcdboot V:Windows /s Z:

Step 7: Disable Paging file and then detach HyperV.VHD
Load the Registry:
Reg load HKLMHyperVTemp V:WindowsSystem32ConfigSystem
Remove paging file (replace the value by an empty value)
C:>reg add “HKLMHyperVTempControlSet001ControlSession ManagerMemory Management” /v PagingFiles /t REG_MULTI_SZ /d “” /f
Delete page files
C:>reg delete “HKLMHyperVTempControlSet001ControlSession ManagerMemory Management” /v ExistingPageFiles /f

Unload the registry
C:>reg unload HKLMHyperVTemp
Now we can detach the VHD file using diskpart.
Diskpart
Select vdisk file=Z:HyperV.vhd
Detach vdisk
exit
Step 8: Verification
Now plug the USB drive to a computer and boot it up from the USB. Ensure to change the boot device sequence in your motherboard BIOS.
The first time you boot it up, the OS will prompt you to change the Administrator’s Password. You should do so at this point.
After all that, we will need to change the Computer Name, configure TCP/IP network settings, Firewall Settings, Date and Time Settings, TimeZone Settings, etc…
