From f3701042c9521800d369d1a0888f503654e262da Mon Sep 17 00:00:00 2001 From: Ben Miller Date: Thu, 19 Jun 2025 14:17:15 -0600 Subject: [PATCH] foam_sync.ps1 (LIFEBALANCE) 2025-06-19T14:17:15Z --- foam_sync.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/foam_sync.ps1 b/foam_sync.ps1 index 82aa721..39e13c7 100644 --- a/foam_sync.ps1 +++ b/foam_sync.ps1 @@ -12,7 +12,8 @@ $scriptName = (Get-Item $scriptPath).Name $taskName = 'FoamGitSync' $taskDescription = "Periodically synchronizes the Git repository at $scriptDir using $scriptName." $fullCommand = "c:\windows\system32\conhost.exe --headless powershell.exe -WindowStyle Hidden -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $scriptPath" -$executeCommand = $fullCommand.Split(" ")[0] +$taskExecute = $fullCommand.Split(" ")[0] +$taskArguments = $fullCommand.Split(" ").Skip(1).Join(" ") $frequencyMinutes = 2 $timeLimitSeconds = 30 @@ -30,8 +31,7 @@ try { # Run as the user who executes this script. $taskPrincipal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes $frequencyMinutes) - $actionArgumentForRegistration = "-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File $scriptPath" - $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $actionArgumentForRegistration + $action = New-ScheduledTaskAction -Execute $taskExecute -Argument $taskArguments # Task settings $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit $(New-TimeSpan -Seconds $timeLimitSeconds) @@ -55,8 +55,8 @@ try { # Check Action $actionMatches = $false if ($currentAction -is [Microsoft.Management.Infrastructure.CimInstance] ` - -and $currentAction.Execute -eq "powershell.exe" ` - -and $currentAction.Argument -eq $expectedRetrievedActionArgument) { + -and $currentAction.Execute -eq $taskExecute ` + -and $currentAction.Argument -eq $taskArguments) { $actionMatches = $true }