diff --git a/playbook/shopfloor-setup/Run-ShopfloorSetup.ps1 b/playbook/shopfloor-setup/Run-ShopfloorSetup.ps1 index fee2da9..800b60f 100644 --- a/playbook/shopfloor-setup/Run-ShopfloorSetup.ps1 +++ b/playbook/shopfloor-setup/Run-ShopfloorSetup.ps1 @@ -50,6 +50,35 @@ Report-Stage -Stage 'Run-ShopfloorSetup: starting' -Index 2 # Cancel any pending reboot so it doesn't interrupt setup cmd /c "shutdown /a 2>nul" *>$null +# Self-resume: register this script as a RunOnce so a vendor-installer- +# forced reboot mid-flight (FormTracePak Setup.exe, eDNC MSI, etc) auto- +# resumes the chain after the next SupportUser auto-login. RunOnce is +# single-shot - if we complete normally we remove this key at end of +# script. If we're killed mid-flight by a forced reboot, the key +# survives and fires after reboot. +# +# Idempotent design throughout this script: every step checks detection +# before installing, so a forced-reboot re-entry just skips the already- +# done work and continues from where it left off. +# +# Also top up AutoLogonCount so the SupportUser autologon budget +# (LogonCount=7 from unattend XML) survives extra unplanned reboots. +$selfResumeKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce' +$selfResumeName = 'ResumeRunShopfloorSetup' +$selfResumeCmd = 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "' + $PSCommandPath + '"' +try { + Set-ItemProperty -Path $selfResumeKey -Name $selfResumeName -Value $selfResumeCmd -Type String -Force -ErrorAction Stop + Write-Host "Self-resume RunOnce registered: will re-fire $PSCommandPath if interrupted" +} catch { + Write-Warning "Failed to register self-resume RunOnce: $_" +} +try { + Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoLogonCount' -Value 10 -Type DWord -Force -ErrorAction Stop + Write-Host "AutoLogonCount topped up to 10 (vendor-forced reboot resilience)" +} catch { + Write-Warning "Failed to top up AutoLogonCount: $_" +} + # Wired NIC state handling moved to sync_intune (Monitor-IntuneProgress.ps1). # Previously this script prompted the tech to unplug the PXE cable and # then re-enabled wired adapters interactively - that blocked the whole @@ -450,6 +479,10 @@ if (Test-Path -LiteralPath $enrollScript) { Report-Stage -Stage 'Run-ShopfloorSetup: handoff to Monitor-IntuneProgress' -Index 6 Write-Host "=== Handing off to Monitor-IntuneProgress -PostPpkg ===" cmd /c "shutdown /a 2>nul" | Out-Null + # Made it past all the reboot-prone vendor installers. Clear the + # self-resume RunOnce so a normal completion + reboot does not re-fire + # this script post-PPKG (PPKG install owns the reboot chain from here). + try { Remove-ItemProperty -Path $selfResumeKey -Name $selfResumeName -ErrorAction SilentlyContinue } catch {} $monitor = Join-Path $setupDir 'Shopfloor\lib\Monitor-IntuneProgress.ps1' if (Test-Path -LiteralPath $monitor) { & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $monitor -PostPpkg @@ -463,6 +496,7 @@ if (Test-Path -LiteralPath $enrollScript) { Write-Host "================================================================" Write-Host "=== Run-ShopfloorSetup.ps1 complete $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ===" Write-Host "================================================================" + try { Remove-ItemProperty -Path $selfResumeKey -Name $selfResumeName -ErrorAction SilentlyContinue } catch {} try { Stop-Transcript | Out-Null } catch {} Write-Host "Rebooting in 10 seconds..." shutdown /r /t 10