diff --git a/foam_sync.ps1 b/foam_sync.ps1 index 0c6c9b6..3aafce4 100644 --- a/foam_sync.ps1 +++ b/foam_sync.ps1 @@ -49,9 +49,10 @@ $taskDescription = "Periodically synchronizes the Git repository at $scriptDir u # Run as the user who executes this script. $taskPrincipal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive - +# Define a very long duration (e.g., 100 years) instead of [TimeSpan]::MaxValue +$practicallyIndefiniteDuration = New-TimeSpan -Days (365 * 100 + 25) # Account for leap years over 100 years # Trigger configuration -$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes $frequencyMinutes) -RepetitionDuration ([TimeSpan]::MaxValue) +$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes $frequencyMinutes) -RepetitionDuration $practicallyIndefiniteDuration # Action configuration: # We use an indirection technique to ensure the window is truly hidden. @@ -110,7 +111,7 @@ try { $triggerMatches = $false if ($currentTrigger -is [Microsoft.Management.Infrastructure.CimInstance] ` -and $currentTrigger.RepetitionInterval.TotalMinutes -eq $frequencyMinutes ` - -and $currentTrigger.RepetitionDuration -eq ([TimeSpan]::MaxValue)) { + -and $currentTrigger.RepetitionDuration -eq $practicallyIndefiniteDuration) { $triggerMatches = $true }