100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Scheduled Tasks and Jobs

Learn the difference between PowerShell background jobs and Windows Scheduled Tasks, and how to create, monitor, and manage both from the command line.

AutomationIntermediate10 min readJul 10, 2026
Analogies

Background Jobs vs Scheduled Tasks

A PowerShell background job, started with Start-Job, runs a script block asynchronously in a separate process on the same machine for the duration of the current session, and its results are retrieved later with Receive-Job; a Windows Scheduled Task, by contrast, is a persistent, OS-level definition that survives reboots and can trigger a script at a specific time, on a recurring schedule, or in response to an event, independent of any PowerShell session being open. Choosing between them depends on whether the work needs to happen right now within a running script (a job) or needs to run reliably in the future even if no one is logged in (a scheduled task).

🏏

Cricket analogy: Start-Job is like bringing on a substitute fielder mid-innings who works alongside the current match, while a Scheduled Task is like a fixture already locked into next season's calendar regardless of who's currently playing.

Working with Background Jobs

Start-Job -ScriptBlock { ... } returns a job object immediately while the script block executes in a child process; Get-Job lists all jobs and their State (Running, Completed, Failed), Receive-Job retrieves the output once it's ready, and -Wait blocks until the job finishes if you need synchronous behavior. Jobs should be cleaned up with Remove-Job once their output has been received, since PowerShell keeps completed job objects and their output in memory until explicitly removed, which can accumulate in long-running sessions or scripts that launch many jobs in a loop.

🏏

Cricket analogy: Get-Job checking State is like glancing at the scoreboard to see if an innings is 'In Progress' or 'Completed' before deciding whether to check the final total.

Creating and Managing Scheduled Tasks

The ScheduledTasks module provides New-ScheduledTaskTrigger to define when a task runs (for example -Daily -At '3:00AM'), New-ScheduledTaskAction to define what it runs (typically powershell.exe with -Argument pointing at a script), and Register-ScheduledTask to combine a trigger, action, and principal into a named task visible in Task Scheduler. Once registered, Get-ScheduledTask, Start-ScheduledTask, Disable-ScheduledTask, and Unregister-ScheduledTask let you inspect, manually trigger, pause, or delete the task entirely, and Get-ScheduledTaskInfo reveals the LastRunTime, LastTaskResult, and NextRunTime for monitoring whether a task is actually succeeding on its schedule.

🏏

Cricket analogy: New-ScheduledTaskTrigger -Daily -At '3:00AM' is like a franchise pre-committing to a fixed training-session time every day of the tour, locked in regardless of who's managing that week.

powershell
# Background job example
$job = Start-Job -ScriptBlock {
    Get-ChildItem -Path 'C:\Data' -Recurse -Filter '*.csv'
}
Get-Job -Id $job.Id
$results = Receive-Job -Id $job.Id -Wait
Remove-Job -Id $job.Id

# Register a daily scheduled task that runs a cleanup script at 3 AM
$action  = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -File "C:\Scripts\Cleanup.ps1"'
$trigger = New-ScheduledTaskTrigger -Daily -At '3:00AM'
Register-ScheduledTask -TaskName 'NightlyCleanup' -Action $action -Trigger $trigger -RunLevel Highest

# Check whether the task last succeeded
Get-ScheduledTaskInfo -TaskName 'NightlyCleanup' | Select-Object LastRunTime, LastTaskResult, NextRunTime

LastTaskResult of 0 means the scheduled task's last run exited successfully; nonzero values are Win32 error codes that indicate a failure, so monitoring scripts should check LastTaskResult -ne 0 to detect silently failing automation.

  • Background jobs (Start-Job) run asynchronously within the current machine and session; scheduled tasks persist across reboots and logins.
  • Get-Job, Receive-Job, and Remove-Job form the lifecycle for creating, retrieving, and cleaning up background jobs.
  • Jobs accumulate in memory until explicitly removed with Remove-Job, so long-running scripts should clean them up.
  • New-ScheduledTaskTrigger defines when a task runs; New-ScheduledTaskAction defines what command it executes.
  • Register-ScheduledTask combines a trigger and action into a named task visible in Task Scheduler.
  • Get-ScheduledTaskInfo reports LastRunTime, LastTaskResult, and NextRunTime for monitoring task health.
  • Disable-ScheduledTask pauses a task without deleting it; Unregister-ScheduledTask removes it permanently.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#PowerShellStudyNotes#ScheduledTasksAndJobs#Scheduled#Tasks#Jobs#Background#StudyNotes#SkillVeris#ExamPrep