Skip to content
Snippets Groups Projects
Commit 0be5c65e authored by Andreas Lindemark's avatar Andreas Lindemark
Browse files

Modified Delay and RandomDelay for triggers @StartOnStartup and $RandomTimes.

Also remove Powershell check.
parent 2eae83d7
No related branches found
No related tags found
No related merge requests found
...@@ -52,7 +52,11 @@ function New-CustomScheduledTask { ...@@ -52,7 +52,11 @@ function New-CustomScheduledTask {
# Create the triggers # Create the triggers
$triggers = @() $triggers = @()
if ($StartOnStartup) { 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) { if ($DailyTimes.Count -gt 0) {
...@@ -99,7 +103,7 @@ if (Test-Command -CommandName "choco") { ...@@ -99,7 +103,7 @@ if (Test-Command -CommandName "choco") {
Write-Host "Chocolatey is already installed." Write-Host "Chocolatey is already installed."
} else { } else {
# Install Chocolatey # Install Chocolatey
Write-Host "Chocolatey is not installed, please install." Write-Host "Chocolatey is not installed, please install. Exiting..."
Exit-PSSession Exit-PSSession
} }
...@@ -149,22 +153,11 @@ if ($pwshPath) { ...@@ -149,22 +153,11 @@ if ($pwshPath) {
$randomTimes = if ($null -ne $taskSettings.RandomTimes) { $taskSettings.RandomTimes } else { @() } $randomTimes = if ($null -ne $taskSettings.RandomTimes) { $taskSettings.RandomTimes } else { @() }
$randomDays = if ($null -ne $taskSettings.RandomDays) { $taskSettings.RandomDays } 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 # Creating a scheduled task to update Chocolatey apps
New-CustomScheduledTask -TaskName "AutoUpdateChocolateyApps" ` New-CustomScheduledTask -TaskName "AutoUpdateChocolateyApps" `
-TaskDescription "Automatically updates all Chocolatey applications on Startup" ` -TaskDescription "Automatically updates all Chocolatey applications on Startup" `
-Execute $pwshPath ` -Execute $pwshPath `
-Argument $startupArgument ` -Argument $argument `
-StartOnStartup $startOnStartup ` -StartOnStartup $startOnStartup `
-StartupDelay $startupDelay ` -StartupDelay $startupDelay `
-DailyTimes $dailyTimes ` -DailyTimes $dailyTimes `
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment