From c1cc8b482e29c523195a3e0610609ba655931ff6 Mon Sep 17 00:00:00 2001 From: Ben Miller Date: Thu, 19 Jun 2025 01:14:24 -0600 Subject: [PATCH] foam_sync.ps1 (LIFEBALANCE) 2025-06-19T01:14:24Z --- foam_sync.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/foam_sync.ps1 b/foam_sync.ps1 index 1a07b6f..56aa040 100644 --- a/foam_sync.ps1 +++ b/foam_sync.ps1 @@ -95,11 +95,16 @@ try { # 5. Argument string FOR THE TASK SCHEDULER to pass to the first powershell.exe. # The $commandToRunViaStartProcess is the value for -Command, and needs to be quoted for registration. # e.g., -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Start-Process -FilePath powershell.exe -ArgumentList '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File \"C:\path\to your script.ps1\"' -WindowStyle Hidden" - $actionArgumentForRegistration = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command \`"$commandToRunViaStartProcess\`"" + # $actionArgumentForRegistration = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command \`"$commandToRunViaStartProcess\`"" + + # TEMPORARY: For troubleshooting the flashing window. This will create an error log for the intermediate powershell. + $intermediateErrorLog = Join-Path -Path $logDir -ChildPath "intermediate_error.log" + $actionArgumentForRegistration = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command \`"$commandToRunViaStartProcess 2> '$intermediateErrorLog'\`"" + # 6. Expected argument string WHEN RETRIEVED by Get-ScheduledTask. # Task Scheduler/PowerShell often strips the outermost quotes from the -Command value when retrieved. - $expectedRetrievedActionArgument = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command $commandToRunViaStartProcess" + $expectedRetrievedActionArgument = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command $commandToRunViaStartProcess 2> '$intermediateErrorLog'" # Match the temporary change $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $actionArgumentForRegistration