diff --git a/Windows/Chocolatey/ScheduleChocolateyUpgrade.ps1 b/Windows/Chocolatey/ScheduleChocolateyUpgrade.ps1 index 8bc68e02fa05b8228056c8bfc731b1b168eeb0e5..46ad74b9a8c489c7c7cd916f829dbb761eb1bdb9 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 `