Forked from dstreefkerk/Schedule-ChocoUpgradeAll.ps1
Last active
June 2, 2018 06:07
-
-
Save gustybear/982222728ff5e160022088e30d1b44c8 to your computer and use it in GitHub Desktop.
PowerShell script to create a scheduled task that runs a choco upgrade all at machine startup
This file contains hidden or 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
| # See if choco.exe is available. If not, stop execution | |
| $chocoCmd = Get-Command -Name 'choco' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Select-Object -ExpandProperty Source | |
| if ($chocoCmd -eq $null) { break } | |
| # Settings for the scheduled task | |
| $taskAction = New-ScheduledTaskAction -Execute $chocoCmd -Argument 'upgrade all -y' | |
| $taskTrigger = New-ScheduledTaskTrigger -Daily -At 11pm | |
| $taskUserPrincipal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' | |
| $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 | |
| # Set up the task, and register it | |
| $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Trigger $taskTrigger -Settings $taskSettings | |
| Register-ScheduledTask -TaskName 'Run a Choco Upgrade All at 11PM Daily' -InputObject $task -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment