Created
March 13, 2024 16:27
-
-
Save seyerj/947d82adf59776678783c8ec72f101c8 to your computer and use it in GitHub Desktop.
Scheduled task create to update all chocolatey and winget apps at login.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the commands to be scheduled | |
$commands = @( | |
"winget upgrade --all --accept-source-agreements --accept-package-agreements", | |
"choco upgrade all -y" | |
) | |
# Define common task properties | |
$taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '{0}' | |
foreach ($command in $commands) { | |
# Extract the command name for task naming | |
$taskName = "UpgradeTask_" + ($command -split " ")[0] | |
# Create scheduled task for each command, runs as logged in user (Initial script needs to be run as admin) | |
$taskActionWithCommand = $taskAction -f $command | |
Register-ScheduledJob -Name $taskName -ScriptBlock {$taskActionWithCommand} -Trigger (New-JobTrigger -AtLogOn) | |
Write-Host "Scheduled task '$taskName' created successfully." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment