Windows Server 2022 Hyper-V Configuration Guide
Introduction
Hyper-V in Windows Server 2022 provides enterprise-class virtualization capabilities with improved performance, enhanced security features, and better integration with cloud services. This guide covers the complete setup and configuration of Hyper-V on Windows Server 2022.
Prerequisites
- Windows Server 2022 (Standard or Datacenter edition)
- Hardware with virtualization support (Intel VT-x or AMD-V)
- Minimum 4 GB RAM (8 GB or more recommended)
- At least 32 GB free disk space
- SLAT-capable processor for certain features
1. Hardware Requirements Verification
Check Virtualization Support
# Check if virtualization is supported and enabled
Get-ComputerInfo | Select HyperVisorPresent, HyperVRequirementDataExecutionPreventionAvailable, HyperVRequirementSecondLevelAddressTranslation, HyperVRequirementVirtualizationFirmwareEnabled, HyperVRequirementVMMonitorModeExtensions
# Alternative method using systeminfo
systeminfo | findstr /i "hyper"
Enable Virtualization in BIOS/UEFI
- Restart the server
- Enter BIOS/UEFI settings
- Enable:
- Intel VT-x (Intel) or AMD-V (AMD)
- Intel VT-d (Intel) or AMD IOMMU (AMD) for device passthrough
- SLAT/EPT support
2. Installing Hyper-V
Using PowerShell (Recommended)
# Install Hyper-V with management tools
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
# Verify installation
Get-WindowsFeature -Name Hyper-V*
Using Server Manager
- Open Server Manager
- Click "Add roles and features"
- Select "Role-based or feature-based installation"
- Select your server
- Check "Hyper-V" role
- Add required features when prompted
- Complete installation and restart
3. Initial Hyper-V Configuration
Configure Hyper-V Settings
# Set default paths
Set-VMHost -VirtualHardDiskPath "D:\Hyper-V\Virtual Hard Disks" -VirtualMachinePath "D:\Hyper-V\Virtual Machines"
# Configure memory settings
Set-VMHost -MaximumStorageMigrations 4 -MaximumVirtualMachineMigrations 4
# Enable enhanced session mode
Set-VMHost -EnableEnhancedSessionMode $true
# Configure NUMA spanning
Set-VMHost -NumaSpanningEnabled $false
Configure Resource Metering
# Enable resource metering for all VMs
Get-VM | Enable-VMResourceMetering
# View resource usage
Get-VM | Measure-VM
4. Virtual Switch Configuration
Create External Virtual Switch
# List physical network adapters
Get-NetAdapter
# Create external virtual switch
New-VMSwitch -Name "External vSwitch" -NetAdapterName "Ethernet" -AllowManagementOS $true
# Configure bandwidth settings
Set-VMSwitch "External vSwitch" -DefaultFlowMinimumBandwidthWeight 50
Create Internal Virtual Switch
# Create internal switch for host-VM communication
New-VMSwitch -Name "Internal vSwitch" -SwitchType Internal
# Configure IP address for the host
New-NetIPAddress -InterfaceAlias "vEthernet (Internal vSwitch)" -IPAddress 192.168.100.1 -PrefixLength 24
Create Private Virtual Switch
# Create private switch for isolated VM-to-VM communication
New-VMSwitch -Name "Private vSwitch" -SwitchType Private
5. Storage Configuration
Configure Storage Pools
# Get available disks
Get-PhysicalDisk -CanPool $true
# Create storage pool
New-StoragePool -FriendlyName "Hyper-V Storage Pool" -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks (Get-PhysicalDisk -CanPool $true)
# Create virtual disk
New-VirtualDisk -StoragePoolFriendlyName "Hyper-V Storage Pool" -FriendlyName "Hyper-V VMs" -Size 500GB -ResiliencySettingName Mirror -ProvisioningType Thin
# Initialize and format
Get-VirtualDisk -FriendlyName "Hyper-V VMs" | Get-Disk | Initialize-Disk -PartitionStyle GPT
Get-VirtualDisk -FriendlyName "Hyper-V VMs" | Get-Disk | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "Hyper-V-VMs"
Configure Storage QoS
# Create Storage QoS policy
New-StorageQosPolicy -Name "Gold" -MinimumIops 1000 -MaximumIops 5000 -PolicyType Dedicated
New-StorageQosPolicy -Name "Silver" -MinimumIops 500 -MaximumIops 2500 -PolicyType Dedicated
New-StorageQosPolicy -Name "Bronze" -MinimumIops 100 -MaximumIops 1000 -PolicyType Dedicated
6. Creating Virtual Machines
Create Generation 2 VM
# Create new VM
New-VM -Name "WebServer01" -MemoryStartupBytes 4GB -Generation 2 -NewVHDPath "D:\Hyper-V\Virtual Hard Disks\WebServer01.vhdx" -NewVHDSizeBytes 100GB -SwitchName "External vSwitch"
# Configure VM settings
Set-VM -Name "WebServer01" -ProcessorCount 4 -DynamicMemory -MemoryMinimumBytes 2GB -MemoryMaximumBytes 8GB -CheckpointType Production
# Add DVD drive for OS installation
Add-VMDvdDrive -VMName "WebServer01" -Path "C:\ISO\WindowsServer2022.iso"
# Configure boot order
$dvd = Get-VMDvdDrive -VMName "WebServer01"
Set-VMFirmware -VMName "WebServer01" -FirstBootDevice $dvd
# Enable nested virtualization (if needed)
Set-VMProcessor -VMName "WebServer01" -ExposeVirtualizationExtensions $true
# Configure automatic start/stop
Set-VM -Name "WebServer01" -AutomaticStartAction Start -AutomaticStartDelay 30 -AutomaticStopAction ShutDown
Create VM from Template
# Export VM as template
Export-VM -Name "Template-Windows2022" -Path "D:\Templates"
# Import as new VM
$vm = Import-VM -Path "D:\Templates\Template-Windows2022\Virtual Machines\[GUID].vmcx" -Copy -GenerateNewId -VhdDestinationPath "D:\Hyper-V\Virtual Hard Disks" -VirtualMachinePath "D:\Hyper-V\Virtual Machines"
Rename-VM -VM $vm -NewName "WebServer02"
7. Advanced Networking
Configure SR-IOV
# Enable SR-IOV on virtual switch
Set-VMSwitch "External vSwitch" -EnableIov $true
# Enable SR-IOV on VM network adapter
Set-VMNetworkAdapter -VMName "WebServer01" -IovWeight 100
Configure SET (Switch Embedded Teaming)
# Create SET-enabled switch
New-VMSwitch -Name "SET-vSwitch" -NetAdapterName "Ethernet", "Ethernet 2" -EnableEmbeddedTeaming $true -AllowManagementOS $true
# Configure load balancing
Set-VMSwitchTeam -Name "SET-vSwitch" -LoadBalancingAlgorithm HyperVPort
VLAN Configuration
# Configure VLAN for VM
Set-VMNetworkAdapterVlan -VMName "WebServer01" -Access -VlanId 100
# Configure trunk mode for multiple VLANs
Set-VMNetworkAdapterVlan -VMName "Router-VM" -Trunk -AllowedVlanIdList "100,200,300" -NativeVlanId 1
8. Storage Features
Configure Deduplication
# Install deduplication feature
Install-WindowsFeature -Name FS-Data-Deduplication
# Enable deduplication on volume
Enable-DedupVolume -Volume "D:" -UsageType HyperV
# Configure deduplication schedule
Set-DedupSchedule -Name "BackgroundOptimization" -Days Monday,Tuesday,Wednesday,Thursday,Friday -Start 22:00 -DurationHours 6
Storage Replica Configuration
# Install Storage Replica feature
Install-WindowsFeature -Name Storage-Replica -IncludeManagementTools -Restart
# Configure replication partnership
New-SRPartnership -SourceComputerName "HyperV01" -SourceRGName "RG01" -SourceVolumeName "D:" -DestinationComputerName "HyperV02" -DestinationRGName "RG02" -DestinationVolumeName "D:" -LogVolumeName "L:" -LogSizeInBytes 8GB
9. High Availability
Configure Hyper-V Replica
# Enable Hyper-V Replica on primary server
Set-VMReplicationServer -ReplicationEnabled $true -AllowedAuthenticationType Kerberos -ReplicationAllowedFromAnyServer $false -DefaultStorageLocation "D:\Hyper-V\Replica"
# Configure firewall
Enable-NetFirewallRule -DisplayName "Hyper-V Replica*"
# Enable replication for VM
Enable-VMReplication -VMName "WebServer01" -ReplicaServerName "HyperV02.domain.com" -ReplicaServerPort 80 -AuthenticationType Kerberos -CompressionEnabled $true -RecoveryHistory 4
Live Migration Configuration
# Enable live migration
Enable-VMMigration
# Configure authentication
Set-VMMigrationNetwork 192.168.1.0/24 -AuthenticationType Kerberos
# Set performance options
Set-VMHost -MaximumVirtualMachineMigrations 4 -MaximumStorageMigrations 4 -VirtualMachineMigrationPerformanceOption SMB
10. Security Configuration
Shielded VMs
# Install Host Guardian Service
Install-WindowsFeature -Name HostGuardianServiceRole -IncludeManagementTools
# Create guardian
New-HgsGuardian -Name "HGS_Guardian" -GenerateCertificates
# Configure VM as shielded
Set-VM -Name "SecureVM01" -EnableShielding $true
Encrypted Virtual Networks
# Configure encrypted virtual network
$cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Subject -like "*HGS*"}
Set-VMNetworkAdapter -VMName "SecureVM01" -EncryptionEnabled $true -CertificateThumbprint $cert.Thumbprint
11. Performance Optimization
Configure Dynamic Memory
# Optimize memory settings
Set-VM -Name "WebServer01" -DynamicMemory -MemoryStartupBytes 2GB -MemoryMinimumBytes 1GB -MemoryMaximumBytes 8GB -MemoryBuffer 20
# Configure memory weight
Set-VMMemory -VMName "WebServer01" -Priority 80
CPU Configuration
# Configure processor settings
Set-VMProcessor -VMName "WebServer01" -Count 4 -Reserve 10 -Maximum 100 -RelativeWeight 200
# Enable processor compatibility for migration
Set-VMProcessor -VMName "WebServer01" -CompatibilityForMigrationEnabled $true
Disk Performance
# Configure disk QoS
Set-VMHardDiskDrive -VMName "WebServer01" -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -MaximumIOPS 5000 -MinimumIOPS 1000
# Enable write-back cache
Set-VMHardDiskDrive -VMName "WebServer01" -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -CacheEnabled $true
12. Monitoring and Management
Configure Performance Monitoring
# Create data collector set
$datacollector = New-Object -ComObject Pla.DataCollectorSet
$datacollector.DisplayName = "Hyper-V Performance"
$datacollector.Duration = 300
$datacollector.SubdirectoryFormat = 1
$datacollector.SubdirectoryFormatPattern = "yyyy-MM-dd"
$datacollector.RootPath = "C:\PerfLogs\Hyper-V"
# Add performance counters
$collector = $datacollector.DataCollectors.CreateDataCollector(0)
$collector.FileName = "Hyper-V_Performance"
$collector.FileNameFormat = 0
$collector.FileNameFormatPattern = "yyyy-MM-dd_HH-mm-ss"
$collector.PerformanceCounters = @(
"\Hyper-V Hypervisor\*",
"\Hyper-V Virtual Machine Health Summary\*",
"\Hyper-V Virtual Network Adapter(*)\*",
"\Hyper-V Virtual Storage Device(*)\*"
)
$datacollector.DataCollectors.Add($collector)
$datacollector.Commit("Hyper-V Performance", $null, 0x0003)
PowerShell Direct
# Connect to VM using PowerShell Direct
$cred = Get-Credential
Invoke-Command -VMName "WebServer01" -Credential $cred -ScriptBlock {
Get-Service | Where-Object {$_.Status -eq "Running"}
}
# Copy files to VM
Copy-VMFile -Name "WebServer01" -SourcePath "C:\Scripts\Configure.ps1" -DestinationPath "C:\Scripts\Configure.ps1" -CreateFullPath -FileSource Host
13. Backup and Recovery
Configure Hyper-V Backup
# Install Windows Server Backup
Install-WindowsFeature -Name Windows-Server-Backup
# Create backup policy
$policy = New-WBPolicy
Add-WBSystemState -Policy $policy
Add-WBBareMetalRecovery -Policy $policy
$virtualMachines = Get-WBVirtualMachine | Where-Object {$_.VMName -like "*"}
Add-WBVirtualMachine -Policy $policy -VirtualMachine $virtualMachines
# Set backup schedule
Set-WBSchedule -Policy $policy -Schedule 02:00
# Set backup target
$target = New-WBBackupTarget -NetworkPath "\\BackupServer\Hyper-V-Backups"
Add-WBBackupTarget -Policy $policy -Target $target
# Enable the policy
Set-WBPolicy -Policy $policy
Checkpoint Management
# Configure checkpoint settings
Set-VM -Name "WebServer01" -CheckpointType Production -AutomaticCheckpointsEnabled $false
# Create checkpoint
Checkpoint-VM -Name "WebServer01" -SnapshotName "Pre-Update $(Get-Date -Format 'yyyy-MM-dd')"
# List checkpoints
Get-VMSnapshot -VMName "WebServer01"
# Apply checkpoint
Restore-VMSnapshot -Name "Pre-Update 2024-01-15" -VMName "WebServer01" -Confirm:$false
14. Troubleshooting
Common Diagnostics
# Check Hyper-V event logs
Get-WinEvent -LogName "Microsoft-Windows-Hyper-V-*" | Where-Object {$_.Level -le 3} | Select-Object -First 50
# Test VM connectivity
Test-VMNetworkAdapter -VMName "WebServer01" -Receiver -SenderIPAddress 192.168.1.10 -ReceiverIPAddress 192.168.1.20
# Validate configuration
Test-VMReplication -VMName "WebServer01"
# Check resource usage
Get-VM | Select-Object Name, State, CPUUsage, MemoryAssigned, MemoryDemand, MemoryStatus
Performance Analysis
# Analyze VM performance
Measure-VM -VMName * | Format-Table -AutoSize
# Check storage latency
Get-StorageSubsystem | Get-StorageHealthReport
# Network statistics
Get-VMNetworkAdapter -VMName * | Select-Object VMName, Name, MacAddress, Status, IPAddresses
Best Practices Summary
- Planning
- Size host hardware appropriately
- Use Generation 2 VMs when possible
-
Plan network architecture before deployment
-
Performance
- Use fixed VHDs for production workloads
- Configure anti-affinity rules for clustered VMs
-
Monitor and adjust dynamic memory settings
-
Security
- Enable shielded VMs for sensitive workloads
- Use encrypted networks
-
Implement proper VLAN segmentation
-
Availability
- Configure Hyper-V Replica for DR
- Use failover clustering for HA
-
Regular backup testing
-
Management
- Use Windows Admin Center for GUI management
- Automate with PowerShell
- Implement proper monitoring