How to Create a Generation 2 Hyper-V Virtual Machine with PowerShell
Applies to: Windows Server 2019, 2022 and 2025.
Generation 2 VMs support UEFI and Secure Boot for modern Windows guests. Resource, disk and network settings should follow workload requirements.
Hyper-V changes affect network and workload availability. Keep console access and tested VM backups. Visit networkmanager.info for managed Windows VPS services.
Prerequisites
- Create VM and VHDX storage paths.
- Prepare authorized installation media.
- Choose memory, CPU and switch.
- Confirm guest OS supports Generation 2.
Procedure
Step 1: Create the VM
Use new VHDX and approved startup memory.
New-VM -Name 'APP01' -Generation 2 -MemoryStartupBytes 4GB -NewVHDPath 'E:\VHDX\APP01.vhdx' -NewVHDSizeBytes 100GB -SwitchName 'External-LAN'Step 2: Configure CPU and dynamic memory
Set workload values.
Set-VMProcessor -VMName 'APP01' -Count 4
Set-VMMemory -VMName 'APP01' -DynamicMemoryEnabled $true -MinimumBytes 2GB -StartupBytes 4GB -MaximumBytes 8GBStep 3: Attach ISO
Mount installation media.
Add-VMDvdDrive -VMName 'APP01' -Path 'D:\ISO\WindowsServer.iso'Step 4: Set boot order
Boot from virtual DVD for installation.
Step 5: Start and install guest
Use VMConnect or remote console.
Verification
Review VM generation, state, resources, disks and network.
Get-VM -Name APP01
Get-VMProcessor APP01
Get-VMMemory APP01
Get-VMHardDiskDrive APP01
Get-VMNetworkAdapter APP01Rollback
Stop and Remove-VM only when the VM is confirmed disposable. Removing the VM does not automatically remove every attached disk; handle data through an approved deletion process.
Operational notes
Use checkpoints and backup as separate controls; neither replaces application-consistent recovery.
Official references
Explore Netcloud24 Canada.