Skip to content

Instantly share code, notes, and snippets.

@rwp0
Last active November 15, 2024 02:14
Show Gist options
  • Save rwp0/d69a0b192998f7462ad5c54655e56a8f to your computer and use it in GitHub Desktop.
Save rwp0/d69a0b192998f7462ad5c54655e56a8f to your computer and use it in GitHub Desktop.
Schedule a daily task with PowerShell
$action = New-ScheduledTaskAction -Execute 'powershell.exe' `
-Argument 'Stop-Computer -Force'
$trigger = New-ScheduledTaskTrigger -Daily `
-At '2:30 AM'
$task = Register-ScheduledTask -TaskName 'Shutdown' `
-Description 'Shutting the PC down at night' `
-Action $action `
-Trigger $trigger `
-Force
# Documentation:
# https://learn.microsoft.com/en-us/powershell/module/scheduledtasks/register-scheduledtask
# Run as:
# pwsh .\schedule.ps1
# Reference
# https://stackoverflow.com/questions/67059634/how-to-schedule-a-task-to-shutdown-a-pc-every-day
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment