Powershell - Create a virtual machine for Windows 11 with Hyper-V

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!


Here’s how to create a virtual machine in Hyper-V ready to host Windows 11 using Hyper-V.

You can get an ISO of Windows 11 here :


Start by checking and adapting the $Name, $RootVmsPath and $IsoPath variables set at the beginning of the script.

Make sure you are using an account with sufficient rights and that you have Hyper-V installed.

The resources defined (RAM, processor and disk size) meet the minimum requirements for Windows 11, but you can specify more.

Once all the code has been run, you just need to connect the virtual machine to a network (if necessary) and follow the Windows 11 installation process.

## Variable definition
# VM name
$Name = 'Windows_11
# VM storage path
# A folder with the name of the VM will be created in this folder,
# the VM configuration and the VHDX will be placed in this folder
# This folder must exist
$RootVmsPath = 'c:\vm'
# Full path to the VHDX
$VhdxPath = '{0}\{1}\{1}.vhdx' -f $RootVmsPath,$Name
# Windows 11 ISO path
$IsoPath = "C:\iso\windows_11.iso"
# Importing the Hyper-V module
Import-Module -Name Hyper-V

# Creation of the virtual machine
New-VM -Name $Name -MemoryStartupBytes 4GB -NewVHDPath $VhdxPath -NewVHDSizeBytes 64GB `
-Path $VmPath -Generation 2 

#Changing the number of processors
Set-VM -Name $Name -ProcessorCount 2

# Load the Windows 11 ISO into a DVD drive and retrieve the DVD drive identifier
$DvdID = Add-VMDvdDrive -VMName $Name -Path $IsoPath -Passthru
# Place the DVD drive 1st in the boot sequence
Set-VMFirmware -VMName $Name -BootOrder $DvdID
# Create a key protector
Set-VMKeyProtector -VMName $Name -NewLocalKeyProtector
# Activate the TPM module
Enable-VMTPM -VMName $Name

# Connect to the VM
vmconnect.exe $env:COMPUTERNAME $Name  

# Start the VM
# Make sure you have the VM window available to press a key to start the DVD
Start-VM -VMName $Name   

Related links