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!
Hello,
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 :
https://www.microsoft.com/en-us/software-download/windows11
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 moduleImport-Module -Name Hyper-V
# Creation of the virtual machineNew-VM -Name $Name -MemoryStartupBytes 4GB -NewVHDPath $VhdxPath -NewVHDSizeBytes 64GB `-Path $VmPath -Generation 2
#Changing the number of processorsSet-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 sequenceSet-VMFirmware -VMName $Name -BootOrder $DvdID
# Create a key protectorSet-VMKeyProtector -VMName $Name -NewLocalKeyProtector
# Activate the TPM moduleEnable-VMTPM -VMName $Name
# Connect to the VMvmconnect.exe $env:COMPUTERNAME $Name
# Start the VM# Make sure you have the VM window available to press a key to start the DVDStart-VM -VMName $Name
Related links
Powershell - Hyper-V - Managing virtual machine configuration versions
How to update the configuration version of a virtual machine so that it can use the new features available on your new Hyper-VPowershell - Create a virtual machine for Windows 11 with Hyper-V
Here's how to create a virtual machine in Hyper-V ready to host a Windows 11 using Hyper-VPowershell - Managing System Restore Points in Windows
How to manage system restore points in WindowsPowershell - Hyper-V - Give a custom name to a virtual network adapter
Hyper-V defaults to naming virtual machine NICs as network adapters. This can make it difficult to identify their usage, but this problem can be solved with Powershell which allows you to change the name of virtual network adapters.PowerShell - Hyper-V - Adding comments to a virtual machine
To keep track of changes to virtual machines under Hyper-V, it may be useful to use the comments function and add any information you think might be usefulHyper-V - Single and extended session modes
A new video to introduce single and extended session modes in Hyper-V
Follow me on
Support me
Last content
Powershell - Testing network connectivity and port accessibility
Powershell - Display network connections (equivalent to netstat)
Powershell - Testing name resolution (equivalent to nslookup)
Powershell - View and manage DNS configuration of network interfaces
Powershell - Managing IP configuration of network interfaces
Powershell - Managing the status and configuration of network interfaces
Powershell and the Left Hand Side
Powershell - Managing disks, partitions and volumes