guide · static export
PC · hyper-v

Create a Hyper-V Virtual Machine with PowerShell

Hyper-V gives you a throwaway Windows or Linux machine in about twenty minutes. Enable the feature, build an internal NAT switch, create the VM from cmdlets and take a snapshot you can roll back to.

by@guidox updated:10/31/26 time:40 min level:Advanced tested on:Windows 11 24H2 Pro works on:Windows 10 Pro, Windows 11 Pro, Windows Server 2019 tools:PowerShell as administrator, Hyper-V Manager
TL;DR

Enable **Microsoft-Hyper-V-All**, build an **Internal** switch with a NAT route, create the disk and VM with **New-VM**, then take a **Checkpoint-VM** before the first boot so you can roll back in one command.

Before you start

Requirements

  • Windows 11 Pro, Enterprise or Education
  • Virtualisation enabled in the BIOS
  • 16 GB RAM recommended
  • 40 minutes
Step by step

Instructions

01

Confirm the hardware can host a VM

**Get-ComputerInfo** reports the virtualisation flags the hypervisor needs. If either VMMonitorModeExtensions or VirtualizationFirmwareEnabled is false, the BIOS setting is the blocker.

Get-ComputerInfo -Property HyperV*,CsNumberOfLogicalProcessors,CsTotalPhysicalMemory | Format-List
systeminfo | findstr /i "Hyper-V"
02

Enable the feature and reboot

**Microsoft-Hyper-V-All** installs the management tools and the hypervisor in one step. The feature is unavailable on Home editions, and the cmdlet says so instead of failing silently.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All -NoRestart
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All | Select-Object State
Get-VMHost | Select-Object ComputerName,VirtualMachinePath,VirtualHardDiskPath
03

Build an internal switch with its own NAT

An **Internal** switch keeps the guest off your LAN until you decide otherwise. **New-NetNat** then gives that switch an address range so the VM reaches the internet through the host.

New-VMSwitch -Name 'LabNet' -SwitchType Internal
$if = Get-NetAdapter -Name 'vEthernet (LabNet)'
New-NetIPAddress -IPAddress 192.168.77.1 -PrefixLength 24 -InterfaceIndex $if.ifIndex
New-NetNat -Name 'LabNat' -InternalIPInterfaceAddressPrefix 192.168.77.0/24
Get-NetNat | Select-Object Name,InternalIPInterfaceAddressPrefix
04

Create the disk and the VM

**New-VHD** creates a dynamically expanding disk, and **New-VM** attaches it with the memory and generation you ask for. Generation 2 is the UEFI variant and the right default today.

New-Item -ItemType Directory C:\VMs\Lab01 -Force | Out-Null
New-VHD -Path C:\VMs\Lab01\disk.vhdx -SizeBytes 60GB -Dynamic
New-VM -Name Lab01 -MemoryStartupBytes 4GB -Generation 2 -VHDPath C:\VMs\Lab01\disk.vhdx -SwitchName 'LabNet'
Set-VMProcessor -VMName Lab01 -Count 2
Set-VMMemory -VMName Lab01 -DynamicMemoryEnabled $true -MinimumBytes 2GB -MaximumBytes 6GB
05

Attach an ISO and boot once

The DVD drive is added as a virtual device, then the boot order is set so the installer runs first. **Start-VM** with **Connect-VM** gives you the console window.

Add-VMDvdDrive -VMName Lab01 -Path D:\iso\Windows11.iso
$dvd = Get-VMDvdDrive -VMName Lab01
Set-VMFirmware -VMName Lab01 -FirstBootDevice $dvd
Start-VM -Name Lab01
vmconnect.exe localhost Lab01
06

Snapshot before you experiment

A checkpoint freezes the disk and memory state, so a broken driver or a bad policy is one **Restore-VMSnapshot** away. Take it after the guest is installed and before you change anything.

Checkpoint-VM -Name Lab01 -SnapshotName 'clean-install'
Get-VMSnapshot -VMName Lab01 | Select-Object Name,CreationTime,SnapshotType
Restore-VMSnapshot -VMName Lab01 -Name 'clean-install' -Confirm:$false
⚠ warningA checkpoint on a busy VM grows the differencing disk quickly. Merge it with Remove-VMSnapshot once the testing is done.
Troubleshooting

Common issues

Enable-WindowsOptionalFeature fails with 0x800f080c

The feature name is wrong for this build. List the available names with Get-WindowsOptionalFeature -Online | Where-Object FeatureName -like '*Hyper*'.

The VM has no network

Check that the switch name matches and that the guest has an address in 192.168.77.0/24. New-NetNat only routes that prefix.

The VM will not boot from the ISO

Generation 2 firmware needs the DVD drive first in the boot order and the ISO attached to a DVD device, not to a SCSI disk slot.

Start-VM reports insufficient memory

The host cannot allocate the startup memory. Lower it, or cap the dynamic maximum below half of physical RAM.

FAQ

Frequently asked

Do I need Hyper-V if I only want a sandbox?

Windows Sandbox is lighter for a single throwaway app test. Hyper-V is the better choice when the guest must keep state across reboots or run its own services.

Will Hyper-V slow down my main Windows install?

It adds a thin hypervisor layer under the host. Games lose a few percent in some titles, which is why the dual-boot and gaming crowd often disables it again.

Can I move the VM to another PC?

Yes. Shut it down, copy the folder, then register it with Import-VM -Path on the new host. The virtual switch name must exist there too.

How to undo this

Remove the VM with Remove-VM -Name Lab01 -Force and delete C:\VMs\Lab01. Then remove the NAT with Remove-NetNat -Name LabNat, delete the switch with Remove-VMSwitch -Name 'LabNet' -Force, and disable the feature with Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -NoRestart.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress