One PowerShell script that builds a fully unattended Windows 11 VM on Hyper-V. Answer a few questions, and Setup partitions the disk, picks the edition, accepts the EULA, creates a local admin (no Microsoft account), logs in once and optionally turns on RDP. No clicking through OOBE.
From a normal, non-admin PowerShell:
irm https://github.com/PhilippRieth/windows11-hyperv-deploy/releases/latest/download/Deploy-Windows11VM.ps1 | iexThe piped copy does not elevate itself. Instead it:
- Downloads the release file to
%TEMP%\windows11-hyperv-deploy\and checks it against the release'sSHA256SUMS. A mismatch stops everything. - Shows you the SHA256 and asks: review it in Notepad first, elevate without reviewing, or abort.
- Runs that exact file elevated after the UAC prompt.
Already in an admin shell? It skips this and starts the wizard.
$base = 'https://github.com/PhilippRieth/windows11-hyperv-deploy/releases/latest/download'
irm "$base/Deploy-Windows11VM.ps1" -OutFile Deploy-Windows11VM.ps1
irm "$base/SHA256SUMS" # compare with the next line
(Get-FileHash .\Deploy-Windows11VM.ps1).Hash
gh attestation verify .\Deploy-Windows11VM.ps1 --repo PhilippRieth/windows11-hyperv-deploy
notepad .\Deploy-Windows11VM.ps1
powershell -ExecutionPolicy Bypass -File .\Deploy-Windows11VM.ps1| Control | What it covers |
|---|---|
SHA256SUMS, checked before elevating |
Corrupted or swapped downloads. It ships next to the script, so it proves integrity, not origin. |
| Build provenance attestation | Tampered releases. Each release is built from a tagged commit by GitHub Actions and signed via Sigstore. gh attestation verify checks it. |
| Fido pinned to a commit and SHA256 | Upstream changes running on your host unreviewed. A new Fido only runs after the pin is bumped. |
| TLS 1.2 only | Fallback to TLS 1.0/1.1 under old Windows PowerShell defaults. |
| SHA-pinned Actions, Dependabot, PSScriptAnalyzer in CI | Moved tags in the release pipeline and obvious script errors. |
- Prerequisites: elevation, Hyper-V module, and the
vmms/vmcomputeservices (starts them if needed). - Questions: VM name, generation (Gen2 default), vCPUs, fixed RAM, disk size, storage path, virtual switch, edition (Home/Pro), local username and password, computer name, RDP.
- ISO: reuses a verified ISO from an earlier run, uses one you already have, or downloads the official Microsoft ISO through Fido (see ISO cache below).
- Unattend ISO: generates an
autounattend.xmlthat- wipes disk 0 and partitions it (GPT for Gen2, MBR for Gen1),
- bypasses the TPM / Secure Boot / RAM / CPU checks (LabConfig),
- accepts the EULA and uses the edition's generic key (installs, does not activate),
- creates a local admin, skips the online account screens, and logs in once,
- optionally enables Remote Desktop.
- VM: Gen2 gets vTPM and Secure Boot. Gen1 relies on the bypass keys.
- Boot: sets the boot order and gets past the "press any key" prompt (see below).
- Cleanup (optional): waits for the guest to get an IP, then ejects both ISOs and deletes the unattend ISO.
A fresh Gen2 VM normally falls through to Start PXE over IPv4, for two reasons. The script handles both:
- Boot order. Hyper-V puts the empty disk first. The script sets install DVD -> disk -> unattend DVD -> network, and checks it.
- "Press any key to boot from CD or DVD..." UEFI waits about 5 seconds, usually before the
console is even open. The script sends Enter through Hyper-V's virtual keyboard (
Msvm_Keyboard) for about 12 seconds after power-on. Later reboots get no keypress, so they boot from the disk.
Stuck at PXE on an existing VM? Restart it and send the keypresses by hand:
Stop-VM win11-01 -TurnOff -Force; Start-VM win11-01; $cs = Get-CimInstance -Namespace root\virtualization\v2 -ClassName Msvm_ComputerSystem -Filter "ElementName='win11-01'"; $kbd = Get-CimAssociatedInstance -InputObject $cs -ResultClassName Msvm_Keyboard; 1..30 | % { Invoke-CimMethod -InputObject $kbd -MethodName TypeKey -Arguments @{keyCode=[uint32]13} | Out-Null; Start-Sleep -Milliseconds 400 }; vmconnect localhost win11-01Downloaded ISOs go to C:\ProgramData\windows11-hyperv-deploy, a folder owned by Administrators
that standard users can read but not change. Right after each download the script records the
ISO's SHA256 in iso-sha256.txt. On later runs it re-hashes the cached ISO and only offers to reuse
it if the hash still matches, so a swapped or corrupted file never gets attached.
Microsoft refreshes its ISO builds every few months, so there is no fixed hash to pin. This is trust on first download (over HTTPS, from Microsoft). If you bring your own ISO, the script shows its SHA256 so you can compare it with the hash Microsoft publishes on its download page.
An ISO left in %TEMP%\windows11-hyperv-deploy by v1.0.x is offered like your own ISO: attached where it
is and hashed, but never copied into the cache, recorded as verified, or deleted by the elevated script.
Elevated copies and deletes inside a user-writable folder can be redirected with a junction, so the script
doesn't do them. Delete that file yourself once you have a cached download.
- Windows 10/11 Pro/Enterprise or Windows Server with Hyper-V enabled
- Admin rights (the script requests UAC itself)
- Internet access for the download and Fido, unless you bring your own ISO
- About 8 GB free for the ISO, plus the disk size you choose
The script uses Microsoft's published generic (KMS client) keys only to skip the product key page.
They install the right edition but do not activate it. Add a real key under
Settings -> System -> Activation. Home and Pro are included; add more in the $Editions map.
- Plain-text password: Windows Setup reads the account password from
autounattend.xmlon the unattend ISO in plain text. The ISO is built in a new, randomly namedunattend-*folder inside the cache. The folder is created already locked to Administrators, SYSTEM and (later) the VM itself, and the script refuses to continue if it isn't. If you let the script wait for first boot, it deletes the folder. Otherwise remove it yourself:
Get-VMDvdDrive -VMName 'win11-01' | Remove-VMDvdDriveRemove-Item 'C:\ProgramData\windows11-hyperv-deploy\unattend-win11-01-*' -Recurse -Force- RDP: if enabled, it opens the Remote Desktop firewall rules on every network profile. Fine for a lab, worth tightening for anything else.
- Lab use: the TPM / Secure Boot bypass and the autologon are there for test VMs, not production builds.
Each run writes a timestamped log to a logs folder next to the script, or to
%TEMP%\windows11-hyperv-deploy\logs when piped. It records the steps, the settings
and a final RESULT: SUCCESS or RESULT: FAILED line. The password is never logged.
- Dot-source it to call the function yourself:
. .\Deploy-Windows11VM.ps1, thenDeploy-Windows11HyperVVM. - Fido download links expire. If a download fails, run it again for a fresh link.
- Gen1 / BIOS is not supported by Microsoft for Windows 11 but installs with the bypass keys. Use Gen2 unless you have a reason not to.