From 0be5c65ed3a2b628999da281005ec5eb495501c6 Mon Sep 17 00:00:00 2001 From: Andreas Lindemark <andreas.lindemark@liu.se> Date: Mon, 10 Mar 2025 19:41:16 +0100 Subject: [PATCH] Modified Delay and RandomDelay for triggers @StartOnStartup and $RandomTimes. Also remove Powershell check. --- .../Chocolatey/ScheduleChocolateyUpgrade.ps1 | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Windows/Chocolatey/ScheduleChocolateyUpgrade.ps1 b/Windows/Chocolatey/ScheduleChocolateyUpgrade.ps1 index 8bc68e0..46ad74b 100644 --- a/Windows/Chocolatey/ScheduleChocolateyUpgrade.ps1 +++ b/Windows/Chocolatey/ScheduleChocolateyUpgrade.ps1 @@ -52,7 +52,11 @@ function New-CustomScheduledTask { # Create the triggers $triggers = @() if ($StartOnStartup) { - $triggers += New-ScheduledTaskTrigger -AtStartup + if ($StartupDelay) { + $triggers += New-ScheduledTaskTrigger -AtStartup -Delay "00:05:00" + } else { + $triggers += New-ScheduledTaskTrigger -AtStartup + } } if ($DailyTimes.Count -gt 0) { @@ -99,7 +103,7 @@ if (Test-Command -CommandName "choco") { Write-Host "Chocolatey is already installed." } else { # Install Chocolatey - Write-Host "Chocolatey is not installed, please install." + Write-Host "Chocolatey is not installed, please install. Exiting..." Exit-PSSession } @@ -149,22 +153,11 @@ if ($pwshPath) { $randomTimes = if ($null -ne $taskSettings.RandomTimes) { $taskSettings.RandomTimes } else { @() } $randomDays = if ($null -ne $taskSettings.RandomDays) { $taskSettings.RandomDays } else { @() } - # Add -EnableRandomDelay parameter for the startup trigger if needed - $startupArgument = "$argument" - if ($StartupDelay) { - $startupArgument += " -EnableRandomDelay $true" - } - - if (-not $pwshPath) { - Write-Error "The path to PowerShell executable is not set." - return - } - # Creating a scheduled task to update Chocolatey apps New-CustomScheduledTask -TaskName "AutoUpdateChocolateyApps" ` -TaskDescription "Automatically updates all Chocolatey applications on Startup" ` -Execute $pwshPath ` - -Argument $startupArgument ` + -Argument $argument ` -StartOnStartup $startOnStartup ` -StartupDelay $startupDelay ` -DailyTimes $dailyTimes ` -- GitLab