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 {