How to Configure Hyper-V on Windows Server 2019

Hyper-V on Windows Server 2019 is Microsoft’s enterprise-grade hypervisor providing hardware virtualization for running multiple isolated virtual machines on a single physical host. Windows Server 2019 Datacenter edition includes unlimited virtual machine licenses for Windows Server guests, making it cost-effective for large-scale virtualization. Hyper-V supports features like live migration, storage migration, Shielded VMs, Discrete Device Assignment (DDA), and persistent memory (NVDIMM) passthrough.

Hardware Requirements for Hyper-V

Hyper-V requires a processor with hardware virtualization support (Intel VT-x or AMD-V), hardware-enforced Data Execution Prevention (Intel XD or AMD NX bit), and Second Level Address Translation (Intel EPT or AMD RVI). Verify hardware support before installing:

# Check if the processor supports virtualization
systeminfo | findstr /C:"Hyper-V Requirements"

# Or using PowerShell
Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online

# Check virtualization support in detail
$cpu = Get-WmiObject -Class Win32_Processor
$cpu.VirtualizationFirmwareEnabled  # True = BIOS has VT enabled

Installing Hyper-V Role

Install the Hyper-V role and management tools. The host will restart after installation:

# Install Hyper-V role with management tools
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart

# After restart, verify the installation
Get-WindowsFeature -Name Hyper-V*

# Check Hyper-V service status
Get-Service vmms

# View Hyper-V version information
(Get-Command vmms.exe).FileVersionInfo.ProductVersion

Configuring Virtual Switches

Virtual switches connect VMs to networks. There are three types. An External switch connects VMs to the physical network through a physical NIC. An Internal switch connects VMs to each other and to the Hyper-V host but not to external networks. A Private switch connects VMs to each other only, isolating them from the host and external networks:

# List physical network adapters
Get-NetAdapter | Select-Object Name, InterfaceDescription, Status

# Create an external virtual switch (connects VMs to physical network)
New-VMSwitch `
    -Name "External-Production" `
    -NetAdapterName "Ethernet" `
    -AllowManagementOS $true `
    -Notes "External switch for production VMs"

# Create an internal virtual switch (for VM-to-VM and VM-to-host communication)
New-VMSwitch -Name "Internal-Management" -SwitchType Internal

# Create a private switch (isolated VM network for testing)
New-VMSwitch -Name "Private-Test" -SwitchType Private

# List all virtual switches
Get-VMSwitch | Select-Object Name, SwitchType, NetAdapterInterfaceDescription, AllowManagementOS

# Enable VLAN on a virtual switch port (for VLAN tagging)
Set-VMNetworkAdapterVlan -VMName "VM01" -Access -VlanId 100

Creating Virtual Machines

Create VMs using PowerShell for repeatable, scriptable deployments. Generation 2 VMs support UEFI Secure Boot, PXE boot from virtual NIC, and are required for 64-bit Windows Server and Linux guests:

# Create a Generation 2 VM
New-VM `
    -Name "WEB01" `
    -Generation 2 `
    -MemoryStartupBytes 4GB `
    -Path "E:VMs" `
    -NewVHDPath "E:VMsWEB01WEB01-OS.vhdx" `
    -NewVHDSizeBytes 80GB `
    -SwitchName "External-Production"

# Configure dynamic memory
Set-VMMemory `
    -VMName "WEB01" `
    -DynamicMemoryEnabled $true `
    -MinimumBytes 2GB `
    -StartupBytes 4GB `
    -MaximumBytes 8GB `
    -Buffer 20 `
    -Priority 80

# Configure virtual processors
Set-VMProcessor `
    -VMName "WEB01" `
    -Count 4 `
    -Maximum 100 `
    -Reserve 0 `
    -RelativeWeight 100 `
    -CompatibilityForMigrationEnabled $true

# Attach an ISO for OS installation
Add-VMDvdDrive -VMName "WEB01" -Path "E:ISOsWinServer2019.iso"

# Set boot order for Generation 2 VM
Set-VMFirmware -VMName "WEB01" -BootOrder (
    Get-VMDvdDrive -VMName "WEB01",
    (Get-VMHardDiskDrive -VMName "WEB01")
)

# Enable Secure Boot (required for Windows Generation 2 VMs)
Set-VMFirmware -VMName "WEB01" -EnableSecureBoot On -SecureBootTemplate MicrosoftWindows

# Start the VM
Start-VM -Name "WEB01"

Configuring Virtual Hard Disks

Hyper-V supports multiple VHD types. Dynamic VHDs grow as data is written and use less initial space. Fixed VHDs allocate all space at creation and offer better performance. Differencing VHDs use a parent disk and store only changes, useful for test environments:

# Create a new fixed VHD (best performance)
New-VHD -Path "E:VMsWEB01WEB01-Data.vhdx" -SizeBytes 200GB -Fixed

# Create a dynamic VHD
New-VHD -Path "E:VMsWEB01WEB01-Logs.vhdx" -SizeBytes 50GB -Dynamic

# Attach a data disk to a VM
Add-VMHardDiskDrive `
    -VMName "WEB01" `
    -Path "E:VMsWEB01WEB01-Data.vhdx" `
    -ControllerType SCSI `
    -ControllerNumber 0 `
    -ControllerLocation 1

# Expand an existing VHD (VM must be stopped or disk must be a data disk)
Resize-VHD -Path "E:VMsWEB01WEB01-OS.vhdx" -SizeBytes 120GB

# Convert a dynamic VHD to fixed for better performance
Convert-VHD `
    -Path "E:VMsWEB01WEB01-OS.vhdx" `
    -DestinationPath "E:VMsWEB01WEB01-OS-Fixed.vhdx" `
    -VHDType Fixed

Configuring VM Checkpoints (Snapshots)

Checkpoints capture the state of a VM at a point in time. Production checkpoints use Volume Shadow Copy Service (VSS) to create application-consistent checkpoints, while standard checkpoints also save RAM state:

# Set checkpoint type to Production (VSS-consistent)
Set-VM -VMName "WEB01" -CheckpointType Production

# Create a checkpoint before making changes
Checkpoint-VM -VMName "WEB01" -SnapshotName "Pre-Update-$(Get-Date -Format 'yyyy-MM-dd')"

# List checkpoints
Get-VMCheckpoint -VMName "WEB01"

# Revert to a checkpoint
Restore-VMCheckpoint `
    -VMName "WEB01" `
    -Name "Pre-Update-2024-01-15" `
    -Confirm:$false

# Delete a checkpoint (important for performance - checkpoints create differencing disks)
Remove-VMCheckpoint -VMName "WEB01" -Name "Pre-Update-2024-01-15" -Confirm:$false

Configuring Live Migration

Live Migration moves a running VM from one Hyper-V host to another without downtime. Requires both hosts to be domain members with matching CPU families (or Processor Compatibility Mode enabled):

# Enable Live Migration on both hosts
Enable-VMMigration

# Configure Live Migration network (use dedicated NIC if available)
Set-VMMigrationNetwork -Add 192.168.10.0/24

# Set migration authentication and encryption
Set-VMHost `
    -UseAnyNetworkForMigration $false `
    -VirtualMachineMigrationAuthenticationType Kerberos `
    -VirtualMachineMigrationPerformanceOption TCPTransport

# Set maximum concurrent migrations
Set-VMHost -MaximumVirtualMachineMigrations 2

# Perform a Live Migration
Move-VM `
    -Name "WEB01" `
    -DestinationHost "hyperv02.corp.example.com" `
    -IncludeStorage `
    -DestinationStoragePath "E:VMs"

Monitoring Hyper-V Host and VMs

# View all VMs and their state
Get-VM | Select-Object Name, State, CPUUsage, MemoryAssigned, Uptime

# View resource utilization
Get-VM | Get-VMMetrics | Select-Object VMName, AverageProcessorUsage, AggregatedAverageMemoryUsage

# View VM events
Get-WinEvent -LogName "Microsoft-Windows-Hyper-V-VMMS-Operational" -MaxEvents 20

# Check Hyper-V host settings
Get-VMHost | Select-Object ComputerName, LogicalProcessorCount, MemoryCapacity, VirtualMachinePath, VirtualHardDiskPath

# Check VM network traffic
Get-VMNetworkAdapter -VMName "WEB01" | Select-Object VMName, IPAddresses, SwitchName, BandwidthSetting

Hyper-V on Windows Server 2019 provides a mature, enterprise-ready virtualization platform. For production environments, implement a cluster with Failover Clustering to provide VM high availability, use Storage Spaces Direct for hyper-converged storage, and enable Shielded VMs for tenant workloads requiring protection from compromised fabric administrators.