foam_sync.ps1 (LIFEBALANCE) 2025-06-19T14:17:15Z

This commit is contained in:
Ben Miller
2025-06-19 14:17:15 -06:00
parent 1b9ff5334f
commit f3701042c9

View File

@ -12,7 +12,8 @@ $scriptName = (Get-Item $scriptPath).Name
$taskName = 'FoamGitSync' $taskName = 'FoamGitSync'
$taskDescription = "Periodically synchronizes the Git repository at $scriptDir using $scriptName." $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" $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 $frequencyMinutes = 2
$timeLimitSeconds = 30 $timeLimitSeconds = 30
@ -30,8 +31,7 @@ try {
# Run as the user who executes this script. # Run as the user who executes this script.
$taskPrincipal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive $taskPrincipal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes $frequencyMinutes) $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 $taskExecute -Argument $taskArguments
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $actionArgumentForRegistration
# Task settings # Task settings
$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit $(New-TimeSpan -Seconds $timeLimitSeconds) $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit $(New-TimeSpan -Seconds $timeLimitSeconds)
@ -55,8 +55,8 @@ try {
# Check Action # Check Action
$actionMatches = $false $actionMatches = $false
if ($currentAction -is [Microsoft.Management.Infrastructure.CimInstance] ` if ($currentAction -is [Microsoft.Management.Infrastructure.CimInstance] `
-and $currentAction.Execute -eq "powershell.exe" ` -and $currentAction.Execute -eq $taskExecute `
-and $currentAction.Argument -eq $expectedRetrievedActionArgument) { -and $currentAction.Argument -eq $taskArguments) {
$actionMatches = $true $actionMatches = $true
} }