Guest User

Untitled

a guest
Jan 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. # See if choco.exe is available. If not, stop execution
  2. $chocoCmd = Get-Command -Name 'choco' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Select-Object -ExpandProperty Source
  3. if ($chocoCmd -eq $null) { break }
  4.  
  5. # Settings for the scheduled task
  6. $taskAction = New-ScheduledTaskAction -Execute $chocoCmd -Argument 'upgrade all -y'
  7. $taskTrigger = New-ScheduledTaskTrigger -AtStartup
  8. $taskUserPrincipal = New-ScheduledTaskPrincipal -UserId 'SYSTEM'
  9. $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8
  10.  
  11. # Set up the task, and register it
  12. $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Trigger $taskTrigger -Settings $taskSettings
  13. Register-ScheduledTask -TaskName 'Run a Choco Upgrade All at Startup' -InputObject $task -Force
Add Comment
Please, Sign In to add comment