Home / Server / Windows Server / How to Set Up Scheduled Tasks on Windows Server

How to Set Up Scheduled Tasks on Windows Server

Scheduled tasks on Windows Server automate repetitive jobs — running scripts, database maintenance, log cleanup, backups, and health checks — without manual intervention. Here is how to create and manage scheduled tasks reliably on Windows Server.

Open Task Scheduler

Press Win + R and type taskschd.msc, or find it via Server Manager → Tools → Task Scheduler. The left panel shows the task library organised in folders. The Task Scheduler Library folder contains all custom tasks; Windows system tasks live in the Microsoft subfolder.

Create a Scheduled Task (GUI)

  1. In Task Scheduler, click Create Task in the right Actions panel (not “Create Basic Task” — the full dialog gives you more control)
  2. General tab:
    • Give the task a clear name
    • Under Security options, choose the account the task runs as. For scripts that need admin rights, use a service account or choose Run whether user is logged on or not with an administrator account.
    • Tick Run with highest privileges if the task needs administrator elevation
  3. Triggers tab: click New to add a trigger — daily, weekly, monthly, on startup, or on a specific event. Set the start time and recurrence.
  4. Actions tab: click New and choose Start a program. For a PowerShell script:
    • Program: powershell.exe
    • Arguments: -ExecutionPolicy Bypass -NonInteractive -File "C:\Scripts\maintenance.ps1"

    For a batch file, enter the full path in the Program field directly.

  5. Conditions tab: for server tasks, uncheck Start the task only if the computer is on AC power — servers are always on AC.
  6. Settings tab: configure what happens if the task is already running, and whether to restart on failure. Tick If the task fails, restart every X minutes for tasks that should retry on error.
  7. Click OK — you will be prompted for the account password if the task runs under a specific account

Create a Scheduled Task via PowerShell

# Define the action
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -NonInteractive -File C:\Scripts\cleanup.ps1"

# Define the trigger (daily at 2am)
$trigger = New-ScheduledTaskTrigger -Daily -At "02:00"

# Define settings
$settings = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable:$false -StartWhenAvailable

# Register the task running as SYSTEM
Register-ScheduledTask -TaskName "Daily Cleanup" -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest -User "SYSTEM"

# Register with a specific service account
$cred = Get-Credential
Register-ScheduledTask -TaskName "Daily Cleanup" -Action $action -Trigger $trigger -User $cred.UserName -Password $cred.GetNetworkCredential().Password

Common Trigger Types

# Run daily at 3am
$trigger = New-ScheduledTaskTrigger -Daily -At "03:00"

# Run every Monday at 6am
$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At "06:00"

# Run at system startup
$trigger = New-ScheduledTaskTrigger -AtStartup

# Run every 30 minutes
$trigger = New-ScheduledTaskTrigger -RepetitionInterval (New-TimeSpan -Minutes 30) -Once -At (Get-Date)

Run a Task Manually

Right-click any task in Task Scheduler and select Run to execute it immediately. This is useful for testing before relying on the schedule. Check the Last Run Result column — 0x0 means the task completed successfully. Any other value is an error code.

# Run a task via PowerShell
Start-ScheduledTask -TaskName "Daily Cleanup"

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

Running PowerShell Scripts Reliably

PowerShell scripts in scheduled tasks have a few common gotchas:

  • Use full paths for all files and executables — the working directory in a scheduled task is not the same as an interactive session
  • Redirect output to a log file so you can diagnose failures: append *>> C:\Logs\taskname.log to your PowerShell arguments
  • Set the execution policy with -ExecutionPolicy Bypass in the task arguments to avoid the script being blocked by policy
  • Use -NonInteractive to prevent the script waiting for user input that will never come in an unattended session

Sign Up For Daily Newsletter

Stay updated with our weekly newsletter. Subscribe now to never miss an update!

[mc4wp_form]

Leave a Reply

Your email address will not be published. Required fields are marked *