0
0
PowerShellscripting~5 mins

Scheduled scripts with Task Scheduler in PowerShell

Choose your learning style9 modes available
Introduction

Scheduling scripts lets your computer run tasks automatically at set times. This saves you from doing repetitive work manually.

Run a backup script every night while you sleep.
Send daily reports automatically every morning.
Clean temporary files weekly without forgetting.
Check system health regularly without manual effort.
Syntax
PowerShell
schtasks /create /tn "TaskName" /tr "powershell.exe -File C:\Path\To\Script.ps1" /sc schedule_type /st HH:mm

/tn is the task name you choose.

/tr is the command to run your script.

Examples
This creates a task named 'DailyBackup' that runs the backup script every day at 11 PM.
PowerShell
schtasks /create /tn "DailyBackup" /tr "powershell.exe -File C:\Scripts\backup.ps1" /sc daily /st 23:00
This schedules 'WeeklyCleanup' to run every Monday at 2 AM.
PowerShell
schtasks /create /tn "WeeklyCleanup" /tr "powershell.exe -File C:\Scripts\cleanup.ps1" /sc weekly /d MON /st 02:00
Sample Program

This simple PowerShell script prints a message. You can schedule it with Task Scheduler to see it run automatically.

PowerShell
Write-Output "Hello! This script runs on schedule."
OutputSuccess
Important Notes

Make sure your script path is correct and accessible.

Use 24-hour time format for scheduling (e.g., 14:30 for 2:30 PM).

Run Task Scheduler as administrator to create tasks.

Summary

Task Scheduler runs scripts automatically at set times.

Use schtasks /create with task name, script path, schedule, and start time.

Scheduling saves time and avoids forgetting important tasks.