Windows Task Scheduler automates running scripts and programs on a defined schedule — the Windows equivalent of cron on Linux, essential for backups, maintenance scripts, and recurring automation.
Creating a Scheduled Task via PowerShell
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\backup.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At "02:00"
Register-ScheduledTask -TaskName "DailyBackup" -Action $action -Trigger $trigger -RunLevel Highest
Creates a task running a PowerShell script daily at 2:00 AM — -RunLevel Highest runs with elevated (administrator) privileges.
Creating a Task via the Graphical Task Scheduler
taskschd.msc
Opens the graphical interface — useful for less frequent, one-off task creation or when you prefer a visual configuration experience over PowerShell.
Common Trigger Types
# Daily
New-ScheduledTaskTrigger -Daily -At "03:00"
# Weekly, specific days
New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday,Wednesday,Friday -At "09:00"
# At system startup
New-ScheduledTaskTrigger -AtStartup
# Repeating throughout the day
New-ScheduledTaskTrigger -Once -At "00:00" -RepetitionInterval (New-TimeSpan -Hours 1)
Running a Task as a Specific User Account
$principal = New-ScheduledTaskPrincipal -UserId "DOMAIN\serviceaccount" -LogonType Password
Register-ScheduledTask -TaskName "MyTask" -Action $action -Trigger $trigger -Principal $principal
Useful when a task needs to run under a specific service account's context/permissions rather than the default system account.
Viewing Existing Scheduled Tasks
Get-ScheduledTask
Checking a Task's Execution History
Get-ScheduledTaskInfo -TaskName "DailyBackup"
Shows last run time, next scheduled run, and last result code — a non-zero result often indicates the task encountered an error.
Manually Running a Task (For Testing)
Start-ScheduledTask -TaskName "DailyBackup"
Disabling or Removing a Task
Disable-ScheduledTask -TaskName "DailyBackup"
Unregister-ScheduledTask -TaskName "DailyBackup" -Confirm:$false
Configuring Additional Task Settings
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd
Set-ScheduledTask -TaskName "DailyBackup" -Settings $settings
-StartWhenAvailable runs a missed task as soon as possible if the server was off/asleep at the scheduled time, similar in spirit to systemd's Persistent option on Linux.
Logging Task Output
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\backup.ps1 >> C:\Logs\backup.log 2>&1"
Redirect script output to a log file for later review, since Task Scheduler itself doesn't automatically capture detailed script output beyond basic result codes.
Common Errors
Task shows as completed but nothing actually happened — check the task's last result code (0x0 typically means success); a non-zero code indicates an error, and reviewing your script's own logging is the most direct path to understanding what went wrong.
Continue Reading
- PowerShell Basics for Windows Server Administration
- How to Set Up Automated Backups on a Windows VPS
- Windows Server Event Viewer: How to Read and Use Logs
Browse more articles in Windows Server Administration.