Last active
November 15, 2024 02:14
-
-
Save rwp0/d69a0b192998f7462ad5c54655e56a8f to your computer and use it in GitHub Desktop.
Schedule a daily task with PowerShell
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
$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