Skip to content

How to Create a Generation 2 Hyper-V Virtual Machine with PowerShell Print

  • 0

Applies to: Windows Server 2019, Windows Server 2022 and Windows Server 2025, subject to the workload and edition requirements below.

Choose Generation 2 for a supported guest

A Generation 2 Hyper-V VM uses UEFI firmware, supports Secure Boot and boots from virtual SCSI devices. It is a good starting point for supported modern Windows Server guests and many current Linux distributions. Generation is chosen when the VM is created and cannot be changed in place later. Confirm the intended operating system supports Generation 2 before committing its boot disk and installation process.

This guide creates a new Windows Server VM called APP01 with a new VHDX, a reviewed external switch and an installation ISO. It does not clone an existing production server or reuse an unknown disk. Reusing a disk introduces boot-mode, identity and application-consistency questions that require a separate migration procedure. For a template deployment, ensure the source image has been prepared through the supported generalization and provisioning process.

Confirm resources, names and installation media

Use a Hyper-V host with enough available memory, CPU and storage for the VM and operational overhead. A 4 GB startup-memory example is an initial installation choice, not a recommendation for every server application. Choose vCPU and RAM from the application requirements and measured host capacity. Avoid allocating all host memory or an excessive vCPU count merely because a maximum is available.

Verify the ISO comes from an authorized source, matches the intended release and architecture, and is readable by the host. Confirm the guest licensing and activation path. Check that the VM name, configuration directory and VHDX filename are unused; a collision can indicate a previous or active deployment. Select a switch and VLAN whose network is ready for the guest, or use an isolated network during installation when policy requires it.

Get-VM -Name 'APP01' -ErrorAction SilentlyContinue
Get-VMSwitch -Name 'External-LAN'
Get-Volume -DriveLetter D
Test-Path -LiteralPath 'D:\ISO\WindowsServer.iso'
Test-Path -LiteralPath 'D:\Hyper-V\VHDs\APP01-OS.vhdx'

Create a new VM and boot disk explicitly

Run the creation commands from elevated Windows PowerShell on the intended host. Create approved parent directories beforehand. The example creates a new dynamically expanding 80 GB OS disk and associates it with a Generation 2 VM. Its logical maximum is not an immediate guarantee of available physical capacity, so continue to monitor the host volume as the disk grows.

New-Item -ItemType Directory -Path 'D:\Hyper-V\VMs','D:\Hyper-V\VHDs' -Force | Out-Null
New-VM -Name 'APP01' -Generation 2 -MemoryStartupBytes 4GB `
  -Path 'D:\Hyper-V\VMs' `
  -NewVHDPath 'D:\Hyper-V\VHDs\APP01-OS.vhdx' -NewVHDSizeBytes 80GB `
  -SwitchName 'External-LAN'
Set-VMProcessor -VMName 'APP01' -Count 2

If a command fails partway through, inspect Get-VM and the created files before rerunning. Do not delete a same-named VHDX to resolve an error unless you have established that it is the new disposable artifact and contains no needed data. Two vCPUs are illustrative; extra vCPUs do not correct storage latency or insufficient memory.

Set memory policy and preserve a deliberate checkpoint policy

For a predictable starting allocation, keep Dynamic Memory disabled until the application requirements are understood. Some workloads support Dynamic Memory well; others need explicit vendor guidance or different minimum and maximum settings. Changing the policy later should be based on workload behaviour rather than a blanket assumption that dynamic allocation is always better.

Set-VMMemory -VMName 'APP01' -DynamicMemoryEnabled $false -StartupBytes 4GB
Set-VM -Name 'APP01' -CheckpointType ProductionOnly
Get-VM -Name 'APP01' | Select-Object Name,Generation,State,MemoryStartup,ProcessorCount,CheckpointType

ProductionOnly prevents a failed production checkpoint from silently falling back to a standard checkpoint that captures running memory. It does not take a checkpoint now or create an independent backup. The separate checkpoint guide explains guest prerequisites and recovery implications. Also review automatic start and stop actions against the host’s power and maintenance plan; a VM that must start after host recovery should have an intentional dependency and startup-delay policy.

Attach the ISO and configure UEFI boot

New-VM creates a Generation 2 VM without a virtual DVD drive. Add one, attach the reviewed ISO and place that drive first for the installation boot. Keep Secure Boot enabled with the appropriate template for the guest. This Windows example uses the Microsoft Windows template; supported Linux distributions commonly require the Microsoft UEFI Certificate Authority template instead.

Add-VMDvdDrive -VMName 'APP01' -Path 'D:\ISO\WindowsServer.iso'
$dvd = Get-VMDvdDrive -VMName 'APP01'
Set-VMFirmware -VMName 'APP01' -EnableSecureBoot On `
  -SecureBootTemplate 'MicrosoftWindows' -FirstBootDevice $dvd
Get-VMFirmware -VMName 'APP01' | Format-List SecureBoot,SecureBootTemplate,BootOrder

A Secure Boot error should prompt checks of image support, signatures and template selection. Disabling Secure Boot is not a routine first step for a supported Windows installation. If there are multiple DVD drives, select the intended one by its controller location instead of passing an ambiguous collection. Ensure the ISO remains accessible for the duration of setup.

Start setup and complete the guest baseline

Start the VM and open VMConnect or the approved remote console. Follow the installation media’s boot prompt promptly; missing it can send the VM to its next boot device and look like a firmware problem. Install the selected Windows Server edition and complete the initial administrator setup through the secure console.

Start-VM -Name 'APP01'
Get-VM -Name 'APP01' | Select-Object Name,State,Status
Get-VMNetworkAdapter -VMName 'APP01' | Select-Object Name,SwitchName,MacAddress,Status

Inside the guest, install current updates, assign an approved hostname and network configuration, configure time and administrative access, and join the domain only when the identity plan is ready. Do not give the guest a duplicated static address copied from a template. Apply the appropriate security baseline and install application prerequisites selectively. Hyper-V integration components on modern Windows guests are serviced with Windows updates; an old integration-services ISO is not the normal update method.

Verify the installed VM and remove boot-media dependence

Confirm the guest boots from its OS disk, has the intended edition and resources, resolves required DNS names and reaches only its approved network services. Check integration-service status from the host and relevant guest events. A Running VM state means the virtual machine is executing; it does not prove Windows completed startup or the application is healthy.

Get-VMIntegrationService -VMName 'APP01'
Get-VMHardDiskDrive -VMName 'APP01'
Get-VMDvdDrive -VMName 'APP01'
# After installation and successful disk boot:
Set-VMDvdDrive -VMName 'APP01' -Path $null

Remove the ISO from the virtual drive after installation so future reboots do not unexpectedly enter setup. Review the firmware boot order if necessary. Verify a clean guest shutdown and restart, monitor the host’s remaining capacity, and enroll the VM in the intended backup system. A restore test and a documented application acceptance check provide stronger readiness evidence than the initial setup screen.

Diagnose startup failures and remove only disposable artifacts

For no bootable device, inspect the ISO, UEFI compatibility, DVD attachment and firmware order. For insufficient-memory errors, check available host RAM and VM startup requirements. For a disconnected network, verify the virtual adapter’s switch and VLAN and then the guest address; the VM’s generation is rarely the explanation for an ordinary gateway or DNS error. Preserve exact error messages rather than repeatedly changing unrelated settings.

If the deployment is abandoned before real data exists, shut down the new VM and confirm every associated file belongs to this attempt. Remove-VM removes VM registration and configuration; virtual disks require separate handling and must not be deleted indiscriminately. Once the VM contains production data or a domain identity, decommission it through the appropriate application and directory process. Keep configuration, disk location, guest owner, resource choices and recovery responsibilities documented for the next administrator.

Related guidance and official references

Prepare the Hyper-V host; Create the external switch; Configure production checkpoints.


Was this answer helpful?

« Back