# Register-PostPpkgTask.ps1 - register the "GE Shopfloor Post-PPKG" task. # # Called by Run-ShopfloorSetup.ps1 BEFORE the PPKG step (the PPKG reboot can # kill the caller). Copies the runner out of C:\Enrollment (the bulk-enroll # cleanup may remove staging folders) to C:\Program Files\GE\Shopfloor and # registers a SYSTEM task that runs Invoke-PostPpkg.ps1 at every startup and # logon until it has nothing left to do; then it unregisters itself. # # Idempotent: re-registering replaces the task. $ErrorActionPreference = 'Stop' $runtimeDir = 'C:\Program Files\GE\Shopfloor' $taskName = 'GE Shopfloor Post-PPKG' New-Item -Path $runtimeDir -ItemType Directory -Force | Out-Null foreach ($f in @('Install-AppList.ps1', 'Invoke-PostPpkg.ps1')) { Copy-Item -LiteralPath (Join-Path $PSScriptRoot $f) -Destination (Join-Path $runtimeDir $f) -Force } $action = New-ScheduledTaskAction -Execute 'powershell.exe' ` -Argument "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$runtimeDir\Invoke-PostPpkg.ps1`"" $triggers = @( (New-ScheduledTaskTrigger -AtStartup), (New-ScheduledTaskTrigger -AtLogOn) ) $principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries ` -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Hours 2) Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $triggers ` -Principal $principal -Settings $settings -Force | Out-Null Write-Host "Registered '$taskName' (SYSTEM, at startup and logon): $runtimeDir\Invoke-PostPpkg.ps1"