Schedule tasks with Windows Task Scheduler

Create scheduled tasks in Task Scheduler or PowerShell, choose the right account and trigger, and fix tasks that do not run.

  • Intermediate
  • Windows VPS · Admin RDP
  • 2 min read

By RunRacks Team · Published

Task Scheduler runs programs and scripts for you: at startup, at a set time, or when a user signs in. It is the Windows answer to cron and the usual way to automate backups, clean-ups and restarts of your own tools.

Create a task with the graphical tool

  1. Press Windows + R, type taskschd.msc and press Enter.
  2. Click Create Task (not "Create Basic Task", which hides useful options).
  3. General: give it a name. Choose Run whether user is logged on or not for scripts that need no window, and tick Run with highest privileges if the script needs admin rights.
  4. Triggers → New: for example Daily at 03:00, or At startup.
  5. Actions → New: Start a program. For a PowerShell script, program powershell.exe and arguments -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\cleanup.ps1".
  6. Settings: tick If the task fails, restart every 5 minutes if it should retry.
  7. Click OK and enter the account password when asked.

Create the same task in PowerShell

PowerShell
$action  = New-ScheduledTaskAction -Execute "powershell.exe" -Argument '-NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\cleanup.ps1"'
$trigger = New-ScheduledTaskTrigger -Daily -At 3am
Register-ScheduledTask -TaskName "Nightly cleanup" -Action $action -Trigger $trigger -User "SYSTEM" -RunLevel Highest

Run it once now to test, and see the result:

PowerShell
Start-ScheduledTask -TaskName "Nightly cleanup"
Get-ScheduledTaskInfo -TaskName "Nightly cleanup" | Select-Object LastRunTime, LastTaskResult

A LastTaskResult of 0 means success.

Good uses

  • Copy important folders to a backup location every night (backup guide).
  • Delete log files older than 30 days.
  • Restart a service that occasionally hangs.

Troubleshooting

  • Task says it ran but nothing happened: the script probably uses relative paths. Use full paths, or set Start in on the action.
  • Result 0x1: the script itself returned an error. Run the same command by hand in PowerShell to see the message.
  • Task never starts: check the History tab (enable it with Enable All Tasks History in the right panel).

Next steps

Was this guide helpful?

Still stuck?

Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.

Windows VPS & RDP

Allow or block multiple RDP sessions for one user

Understand why a new Remote Desktop login takes over your old session, how the single-session policy works on Windows Server, and which setting suits a team.

  • Advanced
  • Windows VPS
  • 5 min read