Fix stage gate infinite loop: -FromDispatcher bypass
The stage-file gate in Run-ShopfloorSetup.ps1 would fire even when called by Stage-Dispatcher.ps1 (because the stage file still contains "shopfloor-setup"), causing an infinite exit loop. Fix: Run-ShopfloorSetup now accepts -FromDispatcher switch. The gate only fires when the switch is absent (i.e. when called by the unattend's FirstLogonCommands). Stage-Dispatcher passes -FromDispatcher when invoking Run-ShopfloorSetup, bypassing the gate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,13 @@
|
|||||||
# Run-ShopfloorSetup.ps1 - Dispatcher for shopfloor PC type setup
|
# Run-ShopfloorSetup.ps1 - Dispatcher for shopfloor PC type setup
|
||||||
# Runs Shopfloor baseline scripts first, then type-specific scripts on top.
|
# Runs Shopfloor baseline scripts first, then type-specific scripts on top.
|
||||||
|
|
||||||
|
param(
|
||||||
|
# Stage-Dispatcher.ps1 passes -FromDispatcher to bypass the stage-file
|
||||||
|
# gate below. When called by the unattend's FirstLogonCommands (no flag),
|
||||||
|
# the gate defers to the dispatcher if a stage file exists.
|
||||||
|
[switch]$FromDispatcher
|
||||||
|
)
|
||||||
|
|
||||||
# --- Stage-file gate ---
|
# --- Stage-file gate ---
|
||||||
# If run-enrollment.ps1 wrote a stage file, the imaging chain is managed by
|
# If run-enrollment.ps1 wrote a stage file, the imaging chain is managed by
|
||||||
# Stage-Dispatcher.ps1 via RunOnce. Exit immediately so the FirstLogonCommands
|
# Stage-Dispatcher.ps1 via RunOnce. Exit immediately so the FirstLogonCommands
|
||||||
@@ -8,11 +15,13 @@
|
|||||||
# the next boot. Without this gate, the unattend's FirstLogonCommands runs
|
# the next boot. Without this gate, the unattend's FirstLogonCommands runs
|
||||||
# this script right after run-enrollment in the same session (before the
|
# this script right after run-enrollment in the same session (before the
|
||||||
# PPKG reboot), bypassing the entire staged chain.
|
# PPKG reboot), bypassing the entire staged chain.
|
||||||
$stageFile = 'C:\Enrollment\setup-stage.txt'
|
if (-not $FromDispatcher) {
|
||||||
if (Test-Path -LiteralPath $stageFile) {
|
$stageFile = 'C:\Enrollment\setup-stage.txt'
|
||||||
$stage = (Get-Content -LiteralPath $stageFile -First 1 -ErrorAction SilentlyContinue)
|
if (Test-Path -LiteralPath $stageFile) {
|
||||||
Write-Host "Stage file found ($stage) - deferring to Stage-Dispatcher.ps1 on next logon."
|
$stage = (Get-Content -LiteralPath $stageFile -First 1 -ErrorAction SilentlyContinue)
|
||||||
exit 0
|
Write-Host "Stage file found ($stage) - deferring to Stage-Dispatcher.ps1 on next logon."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Transcript logging ---
|
# --- Transcript logging ---
|
||||||
|
|||||||
@@ -89,7 +89,10 @@ switch ($stage) {
|
|||||||
# Run-ShopfloorSetup.ps1 calls shutdown /r /t 10 at the end, which
|
# Run-ShopfloorSetup.ps1 calls shutdown /r /t 10 at the end, which
|
||||||
# gives us a ~10 second window after it returns to advance the stage
|
# gives us a ~10 second window after it returns to advance the stage
|
||||||
# and re-register RunOnce before the reboot fires.
|
# and re-register RunOnce before the reboot fires.
|
||||||
& $script
|
# -FromDispatcher bypasses the stage-file gate at the top of
|
||||||
|
# Run-ShopfloorSetup (which would otherwise see the stage file
|
||||||
|
# and exit immediately thinking it should defer to us).
|
||||||
|
& $script -FromDispatcher
|
||||||
|
|
||||||
Write-Host "Run-ShopfloorSetup.ps1 finished. Advancing stage to sync-intune."
|
Write-Host "Run-ShopfloorSetup.ps1 finished. Advancing stage to sync-intune."
|
||||||
Set-Content -LiteralPath $stageFile -Value 'sync-intune' -Force
|
Set-Content -LiteralPath $stageFile -Value 'sync-intune' -Force
|
||||||
|
|||||||
Reference in New Issue
Block a user