How to Use Task Scheduler to Automate Windows Tasks

6 min read

Automate repetitive Windows tasks with Task Scheduler: run scripts on schedule, at startup, or triggered by events. Covers GUI and PowerShell with practical examples.

Task Scheduler runs programs, scripts, and commands automatically — on a schedule, at startup, when you log in, or when specific events occur. Here's how to use it effectively.


Open Task Scheduler

Win + Rtaskschd.msc

Or: Win + S → search "Task Scheduler"

The left panel shows the task library. Your custom tasks should go in Task Scheduler Library → create a subfolder to keep them organized.


Create a Basic Task (GUI)

ActionCreate Basic Task → follow the wizard:

  1. Name and description — be specific (e.g. "Weekly temp folder cleanup")
  2. Trigger — when to run: Daily, Weekly, Monthly, At startup, At logon, When an event occurs
  3. Action — Start a program / Send an email / Display a message
  4. Browse to your script or executable

For most automation: trigger = Daily or At logon, action = Start a program.


Create a Task via PowerShell

# Run a PowerShell script every day at 3 AM
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
  -Argument "-NonInteractive -WindowStyle Hidden -File C:\Scripts\cleanup.ps1"

$trigger = New-ScheduledTaskTrigger -Daily -At "03:00"

$settings = New-ScheduledTaskSettingsSet `
  -ExecutionTimeLimit (New-TimeSpan -Hours 1) `
  -RunOnlyIfNetworkAvailable $false `
  -StartWhenAvailable $true

Register-ScheduledTask -TaskName "Daily Cleanup" `
  -Action $action `
  -Trigger $trigger `
  -Settings $settings `
  -RunLevel Highest `
  -Force

Practical Examples

Clean temp files weekly

$action = New-ScheduledTaskAction -Execute "cmd.exe" `
  -Argument '/c del /q /f /s "%TEMP%\*"'

$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Sunday -At "02:00"

Register-ScheduledTask -TaskName "Weekly Temp Cleanup" -Action $action -Trigger $trigger -Force

Run a script at startup (before login)

$action = New-ScheduledTaskAction -Execute "powershell.exe" `
  -Argument "-File C:\Scripts\startup.ps1"

$trigger = New-ScheduledTaskTrigger -AtStartup

Register-ScheduledTask -TaskName "Startup Script" `
  -Action $action -Trigger $trigger `
  -User "SYSTEM" -RunLevel Highest -Force

Trigger on event (e.g. USB inserted)

In Task Scheduler GUI: Create TaskTriggersNewOn an event

  • Log: System
  • Source: Microsoft-Windows-DriverFrameworks-UserMode
  • Event ID: 2003 (device connected)

Run Task as SYSTEM (No Window, No Login Required)

When creating the task, set:

  • Security optionsRun whether user is logged on or not
  • Run with highest privileges → checked
  • Configure for: Windows 10/11

This runs the task invisibly in the background even when no user is logged in.


Manage Existing Tasks

# List all custom tasks
Get-ScheduledTask | Where-Object {$_.TaskPath -eq "\"} | Select-Object TaskName, State

# Run a task immediately
Start-ScheduledTask -TaskName "Daily Cleanup"

# Disable without deleting
Disable-ScheduledTask -TaskName "Daily Cleanup"

# Delete
Unregister-ScheduledTask -TaskName "Daily Cleanup" -Confirm:$false

# Check last run result
Get-ScheduledTaskInfo -TaskName "Daily Cleanup" | Select-Object LastRunTime, LastTaskResult

LastTaskResult: 0 = success. Any other value = error.


Troubleshoot Tasks That Don't Run

Check history: In Task Scheduler, select your task → History tab → look for errors.

Enable history if blank: Action menu → Enable All Tasks History

Common issues:

  • Task runs but script fails silently → add logging to your script
  • "The task image is corrupt" → delete and recreate the task
  • Script works manually but not scheduled → check execution policy and use full paths
# Test with full path and explicit execution policy
powershell.exe -ExecutionPolicy Bypass -NonInteractive -File "C:\Scripts\myscript.ps1"

Summary

For one-off automation: use Create Basic Task in the GUI. For scripted or complex setups: use Register-ScheduledTask in PowerShell. Always set Run whether user is logged on or not for background tasks, and check the History tab when something doesn't run as expected.

Related articles

← All articles