Building Your Local Lab: Configuring Hyper-V

**DISCLOSURE: While I am contracted to Microsoft Corporation, I am not an employee. The articles that I write are not meant to represent the company, nor are they meant to represent me as an employee or spokesman for the company. As has always been the case, all articles on this website represent me and nobody else.

**NOTE: All of the command line entries in this article are performed in PowerShell. To differentiate between the PowerShell cmdlets and Command Line Interpreter commands, the PowerShell cmdlets are in blue, and the Commands are in black.

Windows10Configuring a lab environment on Hyper-V in Windows 10 is pretty simple, as long as you know what you need to do. The environment can get pretty complicated, but to get up and running can be as simple as you want it to be.

Setting Your Defaults

1. Storage

If you are working in a laptop and you are always on the go, you might want to store everything on your local hard drive. By default, Hyper-V uses two different folders for storage:

1. Virtual Machine files are stored in “c:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines”

2. Virtual Hard Disk files are stored in “c:\Users\Public\Documents\Hyper-V\Virtual Hard Disks”

Okay, that is fine. I have never really understood why these so interconnected files are stored separately, but whatever. If you are running a single virtual machine, that might not be too bad… running on the system drive and all. However, there are two reasons I like to change the default locations:

  • Keeping the files together (organization); and
  • Separating running virtual machines off the system drive (performance).

While my lab machine was originally purchased (in 2013) for power and portability, it was (even then) heavy and bulky for a laptop, and is now essentially a full-time resident of its docking station, and has not been removed from the dock in a very long time. Unlike most laptops, it has two separate hard drives, which makes it easy to split the spindles. If you only have a single internal hard drive, you might want to invest in an external hard drive… preferably an external SSD.

To change the default file paths for your VMs and VHDX files, run the following cmdlets in an elevated PowerShell window:

Set-VMHost –VirtualMachinePath “D:\Hyper-V\VMs”

Set-VMHost -VirtualHardDiskPath “d:\HyperV\Virtual Hard Disks”

I should mention that even if you are working with the single hard drive, you might want to change the default directories for the sake of simplicity (and organization).

2. Networking

When you enable Hyper-V in Windows 10, it creates a default virtual switch called (predictably) Default Switch. Assuming you have a single network interface card (NIC) on your host computer, it will be configured for that NIC. If you have multiple NICs (many machines will have a physical Ethernet port in addition to the Wi-Fi adapter), then it will pair to the physical NIC. You cannot modify this default switch, so assuming I want to connect my virtual machines to my wireless NIC, I will perform the following (as always, in an elevated PowerShell window:

Get-NetAdapter (I found an adapter called Wi-Fi)

New-VMSwitch -Name BehikeWiFi -NetAdapterName Wi-Fi -AllowManagementOS $true

So we have created a new virtual switch called BehikeWiFi. It is connected to my Wi-Fi NIC. In my Hyper-V Virtual Switch Manager I will see the following:

image

In my Network Connections window I will now see a new adapter that looks like this:

image

Alrighty then! I am ready to build my virtual machines. However, before I do that, there is one last configuration item I like to set.

3. Bonus: Enhanced Session Mode

Enhanced Session Mode allows me to redirect some of my resources of the local devices to my VM, such as sound and enhanced graphics… but it includes the ever important and sought after Clipboard. It is a simple check box, but if you do not set it as a global default, then you will have to modify the configuration of every virtual machine as you go.

Set-VMHost –EnableEnhancedSessionMode $true

I told you that was easy!

In my next article, we will build our first virtual machine, and you will be off to the races!

**Thanks again to my colleague Leslie Falor for proof reading and reminding me that people love the clipboard!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: