Installation
In this article we will install Hyper-V, configures its defaults and setup some basic parameters including network adapters, vSwitches and the management interface.
Install Role
To install Hyper-V via PowerShell, run the following command within an elevated PowerShell prompt.
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
Setting Defaults
By default, Hyper-V will use the following locations to store VM metadata and virtual hard-drives.
- VM Configuration Data:
C:\ProgramData\Microsoft\Windows\Hyper-V
- Virtual Hard-Disks:
C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks
If you wish, you can change these default locations through the following command.
Set-VMHost -VirtualMachinePath "D:\Hyper-V" -VirtualHardDiskPath "D:\Hyper-V\Virtual Hard Disks"
Configure Network Adapter(s)
Prior to setting up any vSwitches, its best to check out and verify your physical network adapters. If you’d like to change the name of these adapters, now would be the best time.
# view all physical network adapters
Get-NetAdapter -Physical
# rename network adapter named 'NIC1'
Rename-NetAdapter -Name "NIC1" -NewName "Gb1"
Configure vSwitch(es)
A virtual switch allows virtual machines to communicate with other computers. It’s through a virtual switch (typically) that you’ll connect your VMs to the physical network.
The following command is an example of creating a new vSwitch called “Internal vSwitch” that will be a trunk port providing connectivity to the various VMs running on the Hyper-V host. In this case, our example vSwitch will be physically tied against our gb1
network adapter.
New-VMSwitch -Name "Internal vSwitch" -NetAdapterName "gb1" -AllowManagementOS $false
Alternatively, if connecting to a NIC Team (aka. LACP link), use this variation of the command.
New-VMSwitch -Name "Internal vSwitch" -NetAdapterName "NICTeamName" -AllowManagementOS $false
Setup Management Interface
The management interface is what allows the hypervisor to communicate on the network. It’s through the management interface that you’ll communicate, connect and manage the Hyper-V host. For some companies, this may be a dedicated network adapter. For others it may be connected to a trunk link on a specified VLAN.
The following command will create a Management virtual network adapter (vNIC) connected to the Internal vSwitch on VLAN 100.
Add-VMNetworkAdapter -Name "Management" -SwitchName "Internal vSwitch" -ManagementOS
Set-VMNetworkAdapterVlan -ManagementOS -Access -VlanID 100
If you want to connect your management vNIC to a specific physical network adapter.
Add-VMNetworkAdapter -Name "Management" -SwitchName "gb1" -ManagementOS