# Register-BulkEnrollTask.ps1 - register the BulkEnrollmentOrchestrator logon task. # # WHY THIS IS A FILE AND NOT AN INLINE COMMAND # This ran as an inline "powershell.exe -Command ..." in the unattend's # specialize pass, at RunSynchronousCommand Order 16. The unattend schema caps # RunSynchronousCommand/Path at 259 characters; the inline form had grown to 676, # so Windows Setup rejected the WHOLE answer file: # # /settings/RunSynchronous/RunSynchronousCommand/[Order="16"]/Path # Description = Value is invalid. hrResult = 0x80220005 pass = specialize # "Windows could not parse or process unattend answer file ... The answer file # is invalid." # # One over-length value blocks every pass, so the machine stops at a dialog with # nothing configured. Every shopfloor build from 2026-08-05 evening onward failed # this way. Keep the unattend's Path short and put logic here. # # PESetup's CopyPackages copies the whole of \Deploy\Applications to the # target before the image is applied, so this script is present at # C:\Deploy\Applications\BPRT\ by the time specialize runs. See # docs/PESETUP-INTERNALS.md. $ErrorActionPreference = 'Stop' $taskName = 'BulkEnrollmentOrchestrator' $orchestrator = 'C:\Deploy\Applications\BPRT\Start-BulkEnrollOrchestrator.ps1' # Self-deleting task: schtasks /Delete removes the registration, then the # orchestrator runs. cmd's & chains them so the delete happens even if the # orchestrator later reboots the machine. $argument = '/c schtasks /Delete /TN {0} /F & powershell.exe -NoProfile -ExecutionPolicy Bypass -File "{1}" -ManualFallback' -f $taskName, $orchestrator $action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument $argument $trigger = New-ScheduledTaskTrigger -AtLogOn # S-1-5-32-544 = BUILTIN\Administrators. GroupId + Highest so it runs elevated # for whichever admin logs on first, without naming an account. $principal = New-ScheduledTaskPrincipal -GroupId 'S-1-5-32-544' -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit (New-TimeSpan -Hours 3) Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force Write-Host "Registered scheduled task '$taskName'."