fix(template): re-affirm autologin after reboot before snapshot

This commit is contained in:
Simone
2026-05-11 21:57:32 +02:00
parent fe2d51f44e
commit cf7274ad20
2 changed files with 28 additions and 0 deletions
+14
View File
@@ -610,6 +610,20 @@ try {
-SessionOption $sessionOptions -UseSSL -Port 5986 ` -SessionOption $sessionOptions -UseSSL -Port 5986 `
-Authentication Basic -ErrorAction Stop -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 # Send graceful shutdown
Write-Host "[Prepare] Sending graceful shutdown to VM..." Write-Host "[Prepare] Sending graceful shutdown to VM..."
try { try {
+14
View File
@@ -610,6 +610,20 @@ try {
-SessionOption $sessionOptions -UseSSL -Port 5986 ` -SessionOption $sessionOptions -UseSSL -Port 5986 `
-Authentication Basic -ErrorAction Stop -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 # Send graceful shutdown
Write-Host "[Prepare] Sending graceful shutdown to VM..." Write-Host "[Prepare] Sending graceful shutdown to VM..."
try { try {