How to run a Windows 11 VM on Hyper-V

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

Happy new year everyone! Last month, before the holidays I wanted to run a Windows 11 VM on Hyper-V to run a few tests on Windows containers in a different environment than my local machine. However, it took me some time to get that VM up and running, simply because I forgot about the new hardware requirements for Windows 11 and that I had to get them configured before I installed the new OS in it. This blog post is my contribution so you don’t have to go through the same!

 

Windows 11 hardware requirements

If you create a regular VM on Hyper-V and try to install Windows 11 on it, this is most likely the screen you’ll get to during the setup:

Win11_HyperV01.png

If you’re interested on the full system requirements for Windows 11, check out the Windows System Requirements page.

Specifically for a regular Hyper-V VM, here are the things you need enabled/configured to get Windows 11 to work:

 

  • Gen 2 VM: As you’ll see below, a TPM and secure boot are required for Windows 11. On Hyper-V, these are only available on Gen 2 VMs, so don’t try to install Windows 11 on a Gen 11 VM.
  • UEFI, Secure Boot capable: Gen 2 VMs have UEFI, which replaces the traditional BIOS on regular Gen 1 VMs. Among other things, it allows for Secure boot which is a security standard developed by members of the PC industry to help make sure that a device boot using only software that is trusted by the Original Equipment Manufacturer (OEM). By default, Secure Boot is enabled on Gen 2 VMs, and the Microsoft Windows template is selected to allow Windows to be installed.
  • TPM 2.0: TPMs have been around for a while, but Windows 11 makes it a requirement – not only a TPM chip, but 2.0 version of it. Since Windows Server 2016, Hyper-V allows VMs to have a virtual TPM chip (You might remember that Shielded VMs uses this feature).

To enable these features on a Hyper-V VM, navigate to the VM Settings, under Security:

Win11_HyperV02.png

Note: Please note the details about Key Protector (KP) configuration above. If you’re running a TPM enabled on a standalone Hyper-V host, a KP will be used to allow that VM to run on the host. On the Hyper-V GUI, this is the default, but the behavior on PowerShell is different – we’ll cover this later in this blog post.

 

Create a Windows 11 VM on Hyper-V via PowerShell

Since a lot of the things we do need to be automated, I thought it would be a good idea to create a PowerShell script to create a Windows 11 capable VM on Hyper-V. That’s when I started to find some differences between the GUI and the PowerShell cmdlets. First, here’s the PowerShell script:

$VMName = Read-Host -Prompt "Please provide the Virtual Machine Name"
$SwitchName = Read-Host -Prompt "Please provide the name of the Virtual Switch to be used"
$ISOFile = Read-Host -Prompt "Please provide the full path for the Windows Server 2022 install media (ISO file)"
$VMPath = Read-Host -Prompt "Please provide the path to store the VM"
New-VM -Name $VMName -Generation 2 -MemoryStartupBytes 4096MB -SwitchName $SwitchName -Path $VMPath -NewVHDPath $VMPath\$VMName\virtualdisk\VHD.vhdx -NewVHDSizeBytes 127000MB
Set-VM -Name $VMName -ProcessorCount 4 -AutomaticCheckpointsEnabled $false
Add-VMDvdDrive -VMName $VMName -Path $ISOFile
$DVDDrive = Get-VMDvdDrive -VMName $VMName
Set-VMFirmware -BootOrder $DVDDrive -VMName $VMName
Set-VMKeyProtector -VMName $VMName -NewLocalKeyProtector
Enable-VMTPM -VMName $VMName

The PowerShell script above starts by asking some information about the VM you want to create, such as VM name, which virtual switch to use, where is the Windows 11 ISO file, and where you want to host this VM. Next, it created the VM with its basic configuration. Notice I have the memory configuration set up to 4GB, which is the minimal requirement for Windows 11, but you can change that if you want. I also have a regular 127GB expanding VHD for VM disk.

 

After creating the VM, we set up some additional config, such as providing 4 virtual processors (which you can change if you need), and I also removed the option of automatic check points (which is a personal preference). Next, we add a new DVD drive, and add the ISO file to it. We then set up the boot order to get the DVD first in line to boot. Notice you’ll still need to press any key once the VM comes up to enter the Windows installation.

 

Finally, we changed the security settings of the VM. Unlike the GUI, on PowerShell you must specify the VM Key Protector configuration – or at least inform that a new one is needed, which is the case of the script above. After that we enable the virtual TPM.

With the script above you should be able to have a Windows 11 capable VM on Hyper-V:

Win11_HyperV03.png

I hope this information is useful and saves you a few minutes when creating a Windows 11 VM on Hyper-V! Let us know in the comments section below!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.