From cf7274ad206bf8d590fdaa059a3c75d282d1dcca Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 11 May 2026 21:57:32 +0200 Subject: [PATCH] fix(template): re-affirm autologin after reboot before snapshot --- template/Prepare-WinBuild2022.ps1 | 14 ++++++++++++++ template/Prepare-WinBuild2025.ps1 | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/template/Prepare-WinBuild2022.ps1 b/template/Prepare-WinBuild2022.ps1 index 2181950..d258b6b 100644 --- a/template/Prepare-WinBuild2022.ps1 +++ b/template/Prepare-WinBuild2022.ps1 @@ -610,6 +610,20 @@ try { -SessionOption $sessionOptions -UseSSL -Port 5986 ` -Authentication Basic -ErrorAction Stop + # Re-affirm autologin — OOBE/first-boot tasks can reset AutoAdminLogon=0 during the reboot. + Write-Host "[Prepare] Re-affirming autologin registry settings..." + Invoke-Command -Session $session -ScriptBlock { + param($user, $pass) + $wlKey = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' + Set-ItemProperty -Path $wlKey -Name AutoAdminLogon -Value '1' -Type String -Force + Set-ItemProperty -Path $wlKey -Name DefaultUserName -Value $user -Type String -Force + Set-ItemProperty -Path $wlKey -Name DefaultDomainName -Value '.' -Type String -Force + if ($pass -ne '') { + Set-ItemProperty -Path $wlKey -Name DefaultPassword -Value $pass -Type String -Force + } + } -ArgumentList $AdminUsername, $AdminPassword + Write-Host "[Prepare] Autologin re-affirmed." -ForegroundColor Green + # Send graceful shutdown Write-Host "[Prepare] Sending graceful shutdown to VM..." try { diff --git a/template/Prepare-WinBuild2025.ps1 b/template/Prepare-WinBuild2025.ps1 index cd3bb5b..e7bca64 100644 --- a/template/Prepare-WinBuild2025.ps1 +++ b/template/Prepare-WinBuild2025.ps1 @@ -610,6 +610,20 @@ try { -SessionOption $sessionOptions -UseSSL -Port 5986 ` -Authentication Basic -ErrorAction Stop + # Re-affirm autologin — OOBE/first-boot tasks can reset AutoAdminLogon=0 during the reboot. + Write-Host "[Prepare] Re-affirming autologin registry settings..." + Invoke-Command -Session $session -ScriptBlock { + param($user, $pass) + $wlKey = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' + Set-ItemProperty -Path $wlKey -Name AutoAdminLogon -Value '1' -Type String -Force + Set-ItemProperty -Path $wlKey -Name DefaultUserName -Value $user -Type String -Force + Set-ItemProperty -Path $wlKey -Name DefaultDomainName -Value '.' -Type String -Force + if ($pass -ne '') { + Set-ItemProperty -Path $wlKey -Name DefaultPassword -Value $pass -Type String -Force + } + } -ArgumentList $AdminUsername, $AdminPassword + Write-Host "[Prepare] Autologin re-affirmed." -ForegroundColor Green + # Send graceful shutdown Write-Host "[Prepare] Sending graceful shutdown to VM..." try {