Find us on social media
Task SchedulerAutomationWindows5 min read
Schedule tasks with Task Scheduler
Automate tasks with Task Scheduler to run scripts on defined schedules or system events.
Task Scheduler automates recurring tasks on Windows Server: backups, maintenance scripts, application restarts and more.
Open Task Scheduler
powershell
taskschd.mscCreate a task via PowerShell
Example 1: Run a script daily at 3 AM
powershell
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\scripts\backup.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At 3:00AM
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd
Register-ScheduledTask -TaskName "Daily Backup" -Action $action -Trigger $trigger -Settings $settings -User "SYSTEM" -RunLevel HighestExample 2: Run every 5 minutes
powershell
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-Command Invoke-WebRequest -Uri http://localhost:3000/health"
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5) -RepetitionDuration (New-TimeSpan -Days 365)
Register-ScheduledTask -TaskName "Health Check" -Action $action -Trigger $trigger -User "SYSTEM"Example 3: Run at system startup
powershell
$action = New-ScheduledTaskAction -Execute "node.exe" -Argument "C:\apps\myapp\index.js" -WorkingDirectory "C:\apps\myapp"
$trigger = New-ScheduledTaskTrigger -AtStartup
$settings = New-ScheduledTaskSettingsSet -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
Register-ScheduledTask -TaskName "Start My App" -Action $action -Trigger $trigger -Settings $settings -User "SYSTEM" -RunLevel HighestManage tasks
powershell
# List all tasks
Get-ScheduledTask | Where-Object {$_.State -ne 'Disabled'}
# Run a task immediately
Start-ScheduledTask -TaskName "Daily Backup"
# Disable a task
Disable-ScheduledTask -TaskName "Health Check"
# Enable a task
Enable-ScheduledTask -TaskName "Health Check"
# Remove a task
Unregister-ScheduledTask -TaskName "Old Task" -Confirm:$falseView task history
powershell
Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational | Select-Object -First 20Troubleshooting
- Task doesn't run: Check "Run whether user is logged on or not" is selected
- Access denied: Use SYSTEM account or ensure the user has "Log on as a batch job" right
- Script doesn't execute: Use full paths and test the command manually first
Tip
For Node.js or Python applications that need to run continuously, Task Scheduler with "At startup" trigger is a simple alternative to installing them as Windows services on your Baires Host VPS.
Was this guide helpful?