@@ -495,7 +495,8 @@ function Receive-CIPPTimerTrigger {
495495 $OrchestratorTable = Get-CIPPTable - TableName ' CippOrchestratorInput'
496496 $OrphanedInputs = Get-CIPPAzDataTableEntity @OrchestratorTable - Filter " PartitionKey eq 'Input'"
497497 $CutoffTime = $UtcNow.AddMinutes (-5 )
498- $StaleOrphans = @ ($OrphanedInputs | Where-Object { $_.Timestamp.DateTime -lt $CutoffTime })
498+ $MaxAge = $UtcNow.AddHours (-24 )
499+ $StaleOrphans = @ ($OrphanedInputs | Where-Object { $_.Timestamp.DateTime -lt $CutoffTime -and $_.Timestamp.DateTime -gt $MaxAge })
499500 if ($StaleOrphans.Count -gt 0 ) {
500501 Write-Information " Found $ ( $StaleOrphans.Count ) orphaned orchestration inputs, re-queuing..."
501502 foreach ($Orphan in $StaleOrphans ) {
@@ -508,6 +509,18 @@ function Receive-CIPPTimerTrigger {
508509 }
509510 Write-LogMessage - API ' TimerFunction' - message " Re-queued $ ( $StaleOrphans.Count ) orphaned orchestration inputs" - sev Info
510511 }
512+ # Clean up orphans older than 24h - too stale to run
513+ $ExpiredOrphans = @ ($OrphanedInputs | Where-Object { $_.Timestamp.DateTime -le $MaxAge })
514+ if ($ExpiredOrphans.Count -gt 0 ) {
515+ Write-Information " Removing $ ( $ExpiredOrphans.Count ) expired orphaned inputs (older than 24h)..."
516+ foreach ($Expired in $ExpiredOrphans ) {
517+ try {
518+ Remove-AzDataTableEntity @OrchestratorTable - Entity $Expired - Force
519+ } catch {
520+ Write-Warning " Failed to remove expired orphan $ ( $Expired.RowKey ) : $ ( $_.Exception.Message ) "
521+ }
522+ }
523+ }
511524 # Mark as completed so we don't scan again
512525 $null = Add-CIPPAzDataTableEntity @OrphanConfigTable - Entity @ {
513526 PartitionKey = ' OrphanRequeue'
0 commit comments