Windows VPS & RDP

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.

IntermediateWindows server2 min read

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.

Warning: Tasks set to run whether the user is logged on or not, or running as SYSTEM, have no visible desktop. Programs with a window, such as MetaTrader or a browser, will not appear. For those, use an At log on trigger and Run only when user is logged on, as shown in Auto-start MetaTrader after a reboot.

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 MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.