How to Set Up Windows Server 2016 Virtual Machine
Creating and configuring virtual machines (VMs) in Windows Server 2016 Hyper-V is a fundamental skill for any system administrator. This guide provides a comprehensive walkthrough of VM creation, hardware configuration, operating system installation, and post-setup tasks using both PowerShell and Hyper-V Manager.
Prerequisites
- Hyper-V role installed on the host server.
- A virtual switch configured (external, internal, or private).
- Adequate disk space for the VM’s virtual hard disk.
- An OS installation ISO or PXE boot infrastructure.
Step 1: Plan VM Specifications
Before creating a VM, plan its resource requirements:
- Generation: Generation 2 is recommended for modern OS (Windows 8/Server 2012+, modern Linux). It uses UEFI firmware and Secure Boot.
- Memory: Use Dynamic Memory for flexible allocation.
- Virtual processors: Match to workload requirements.
- Storage: VHDX format is recommended over the older VHD format.
Step 2: Create the VM with PowerShell
New-VM -Name "WebServer01" `
-Generation 2 `
-MemoryStartupBytes 4GB `
-NewVHDPath "E:VMsWebServer01WebServer01.vhdx" `
-NewVHDSizeBytes 80GB `
-SwitchName "External-vSwitch" `
-Path "E:VMsWebServer01"
Step 3: Configure Processor and Memory
Set-VMProcessor -VMName "WebServer01" -Count 4 -Reserve 10 -Maximum 100
Set-VMMemory -VMName "WebServer01" `
-DynamicMemoryEnabled $true `
-MinimumBytes 1GB `
-StartupBytes 4GB `
-MaximumBytes 16GB `
-Buffer 20
Step 4: Add a DVD Drive and Mount ISO
Add-VMDvdDrive -VMName "WebServer01" -Path "C:ISOsWS2016.iso"
Set the boot order so the VM boots from DVD first:
$bootOrder = @(
(Get-VMDvdDrive -VMName "WebServer01"),
(Get-VMHardDiskDrive -VMName "WebServer01"),
(Get-VMNetworkAdapter -VMName "WebServer01")
)
Set-VMFirmware -VMName "WebServer01" -BootOrder $bootOrder
Step 5: Enable Secure Boot
For Generation 2 VMs, Secure Boot is enabled by default. For Linux VMs, change the Secure Boot template:
Set-VMFirmware -VMName "WebServer01" -EnableSecureBoot On -SecureBootTemplate "MicrosoftWindowsProductionPCClient"
For Linux:
Set-VMFirmware -VMName "WebServer01" -SecureBootTemplate "MicrosoftUEFICertificateAuthority"
Step 6: Add Additional VHD for Data
New-VHD -Path "E:VMsWebServer01Data.vhdx" -SizeBytes 200GB -Dynamic
Add-VMHardDiskDrive -VMName "WebServer01" -Path "E:VMsWebServer01Data.vhdx"
Step 7: Configure Network Adapter Advanced Settings
Set-VMNetworkAdapter -VMName "WebServer01" -DhcpGuard On -RouterGuard On
Set-VMNetworkAdapterVlan -VMName "WebServer01" -Access -VlanId 20
Step 8: Start the VM and Install the OS
Start-VM -Name "WebServer01"
vmconnect.exe localhost "WebServer01"
Complete the OS installation through the VM console. After installation, eject the ISO:
Set-VMDvdDrive -VMName "WebServer01" -Path $null
Step 9: Install Integration Services and Configure
For Windows guests, Integration Services are included automatically. Verify all services are running after OS installation:
Get-VMIntegrationService -VMName "WebServer01" | Select-Object Name, Enabled, PrimaryStatusDescription
Step 10: Export and Import VMs
To back up or migrate a VM by exporting it:
Export-VM -Name "WebServer01" -Path "F:Exports"
To import it on another host:
Import-VM -Path "F:ExportsWebServer01Virtual Machines*.vmcx" -Copy -GenerateNewId
Step 11: Configure VM Automatic Start and Stop Actions
Set-VM -Name "WebServer01" `
-AutomaticStartAction Start `
-AutomaticStartDelay 30 `
-AutomaticStopAction Save
Step 12: Monitor VM Resource Usage
Measure-VM -Name "WebServer01"
Get-VMMemory -VMName "WebServer01"
Get-VMProcessor -VMName "WebServer01"
Summary
Creating and managing virtual machines in Windows Server 2016 Hyper-V provides a powerful platform for workload consolidation and flexible resource management. Using PowerShell for VM lifecycle management enables automation and repeatability, while the Hyper-V Manager GUI provides a visual interface for ad-hoc operations. Key best practices include using Generation 2 VMs, enabling Dynamic Memory, and regularly exporting VMs for backup purposes.