Skip to content

About

Deploy a fully unattended Windows 11 VM on Hyper-V via an autounattend.xml answer file: local admin (no Microsoft account), autologon, optional RDP. Auto-downloads the official ISO via a pinned Fido.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

windows11-hyperv-deploy

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.

Quick start

From a normal, non-admin PowerShell:

irm https://github.com/PhilippRieth/windows11-hyperv-deploy/releases/latest/download/Deploy-Windows11VM.ps1 | iex

The piped copy does not elevate itself. Instead it:

  1. Downloads the release file to %TEMP%\windows11-hyperv-deploy\ and checks it against the release's SHA256SUMS. A mismatch stops everything.
  2. Shows you the SHA256 and asks: review it in Notepad first, elevate without reviewing, or abort.
  3. Runs that exact file elevated after the UAC prompt.

Already in an admin shell? It skips this and starts the wizard.

Verify it yourself first

$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

Supply chain

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.

What it does

  1. Prerequisites: elevation, Hyper-V module, and the vmms / vmcompute services (starts them if needed).
  2. 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.
  3. 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).
  4. Unattend ISO: generates an autounattend.xml that
    • 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.
  5. VM: Gen2 gets vTPM and Secure Boot. Gen1 relies on the bypass keys.
  6. Boot: sets the boot order and gets past the "press any key" prompt (see below).
  7. Cleanup (optional): waits for the guest to get an IP, then ejects both ISOs and deletes the unattend ISO.

Gen2 boot behaviour

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-01

ISO cache

Downloaded 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.

Requirements

  • 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

Editions and keys

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.

Security notes

  • Plain-text password: Windows Setup reads the account password from autounattend.xml on the unattend ISO in plain text. The ISO is built in a new, randomly named unattend-* 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-VMDvdDrive
Remove-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.

Logging

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.

Notes

  • Dot-source it to call the function yourself: . .\Deploy-Windows11VM.ps1, then Deploy-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.

License

MIT

About

Deploy a fully unattended Windows 11 VM on Hyper-V via an autounattend.xml answer file: local admin (no Microsoft account), autologon, optional RDP. Auto-downloads the official ISO via a pinned Fido.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages