foam_sync.ps1 (LIFEBALANCE) 2025-06-19T19:20:07Z
This commit is contained in:
@ -16,20 +16,20 @@ $scriptName = (Get-Item $scriptPath).Name
|
||||
$taskName = 'FoamGitSync'
|
||||
$taskDescription = "Periodically synchronizes the Git repository at $scriptDir using $scriptName."
|
||||
$taskExecute = 'c:\windows\system32\conhost.exe'
|
||||
$taskArguments = "--headless powershell.exe -WindowStyle Hidden -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $scriptPath"
|
||||
$taskArguments = "--headless powershell.exe -WindowStyle Hidden -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $scriptPath -Verbose"
|
||||
$frequencyMinutes = 2
|
||||
$timeLimitSeconds = 30
|
||||
|
||||
if (-not (Test-Path -Path $logDir)) {
|
||||
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
|
||||
}
|
||||
Start-Transcript -Path $logFilePath -Append -IncludeInvocationHeader -Force
|
||||
Start-Transcript -Path $logFilePath -IncludeInvocationHeader -Force
|
||||
|
||||
try {
|
||||
Write-Host "Script: $scriptName at $scriptPath"
|
||||
Write-Host "Repository directory: $scriptDir"
|
||||
Write-Host "Sync frequency: Every $frequencyMinutes minutes"
|
||||
Write-Host "Log file: $logFilePath"
|
||||
Write-Verbose "Script: $scriptName at $scriptPath"
|
||||
Write-Verbose "Repository directory: $scriptDir"
|
||||
Write-Verbose "Sync frequency: Every $frequencyMinutes minutes"
|
||||
Write-Verbose "Log file: $logFilePath"
|
||||
|
||||
# Run as the user who executes this script.
|
||||
$taskPrincipal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive
|
||||
@ -48,9 +48,6 @@ try {
|
||||
Write-Verbose "Principal: $taskPrincipal"
|
||||
Write-Verbose "Settings: $settings"
|
||||
|
||||
|
||||
# Task settings
|
||||
|
||||
# Check and configure the scheduled task
|
||||
try {
|
||||
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
||||
@ -71,7 +68,6 @@ try {
|
||||
Write-Warning "trigger does not match:`n $(Compare-Object -IncludeEqual -ReferenceObject $currentTrigger -DifferenceObject $trigger)"
|
||||
}
|
||||
|
||||
|
||||
# Check Action
|
||||
Write-Host "Checking action..."
|
||||
$actionMatches = $false
|
||||
@ -80,8 +76,11 @@ try {
|
||||
-and $currentAction.Arguments -eq $taskArguments) {
|
||||
$actionMatches = $true
|
||||
}
|
||||
else {
|
||||
Write-Warning "action does not match:`n $(Compare-Object -IncludeEqual -ReferenceObject $currentAction -DifferenceObject $action)"
|
||||
}
|
||||
|
||||
# Check Principal (example, can be expanded)
|
||||
# Check Principal
|
||||
$principalMatches = ($existingTask.Principal.UserId -eq $taskPrincipal.UserId)
|
||||
|
||||
# Check Settings (specifically ExecutionTimeLimit for this change)
|
||||
|
||||
Reference in New Issue
Block a user