Skip to Content
PowerShellScheduled Tasks

Scheduled Tasks

Windows Task Scheduler runs scripts and programs automatically on a defined schedule or in response to system events. PowerShell’s ScheduledTasks module lets you create and manage tasks from the command line, which is useful for automation, remote management, and scripting deployments.

List All Scheduled Tasks

Returns all tasks registered on the system, including built-in Windows tasks. Filter by TaskPath to narrow down to a specific folder.

Get-ScheduledTask | Select-Object TaskName, TaskPath, State | Format-Table -AutoSize

Get Task Details

Returns runtime information for a task — last run time, next run time, last result code, and number of missed runs.

Get-ScheduledTask -TaskName "My Task" | Get-ScheduledTaskInfo

Create a Scheduled Task

Creating a task involves three components: an action (what to run), a trigger (when to run it), and settings (constraints like time limits). These are combined and registered with Register-ScheduledTask.

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\Scripts\MyScript.ps1" $trigger = New-ScheduledTaskTrigger -Daily -At "08:00AM" $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 1) Register-ScheduledTask -TaskName "My Task" -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest

-RunLevel Highest runs the task with elevated privileges. Remove it if admin rights aren’t needed.

Run a Task Immediately

Starts a task on demand regardless of its schedule. Useful for testing or triggering a one-off run.

Start-ScheduledTask -TaskName "My Task"

Stop a Running Task

Terminates a task that is currently executing.

Stop-ScheduledTask -TaskName "My Task"

Enable / Disable a Task

Disabling a task prevents it from running on its schedule without deleting it. Re-enable it when needed.

# Enable Enable-ScheduledTask -TaskName "My Task" # Disable Disable-ScheduledTask -TaskName "My Task"

Delete a Task

Permanently removes a task from Task Scheduler. -Confirm:$false skips the confirmation prompt.

Unregister-ScheduledTask -TaskName "My Task" -Confirm:$false

Export and Import a Task

Tasks are stored as XML, which makes them easy to back up or deploy to other machines. Exporting and re-importing is also useful when migrating tasks between servers.

# Export to XML Export-ScheduledTask -TaskName "My Task" | Out-File "C:\Backups\MyTask.xml" # Import from XML Register-ScheduledTask -TaskName "My Task" -Xml (Get-Content "C:\Backups\MyTask.xml" | Out-String)
Last updated on