The essentials

Quick reference

One focused task per row. Jump to the related section for complete, working examples.

UseSyntaxExamples
List tasksGet-ScheduledTask | Sort-Object TaskPath, TaskNameView examples
Get one exact taskGet-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport'View examples
Inspect runtime informationGet-ScheduledTaskInfo -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport'View examples
Create an action$action = New-ScheduledTaskAction -Execute 'pwsh.exe' ` -Argument '-NoProfile -File C:\Scripts\Export.ps1'View examples
Create a daily trigger$trigger = New-ScheduledTaskTrigger -Daily -At '02:00'View examples
Create a startup trigger$trigger = New-ScheduledTaskTrigger -AtStartupView examples
Run as a service account$principal = New-ScheduledTaskPrincipal -UserId ` 'NT AUTHORITY\SYSTEM' -LogonType ServiceAccount ` -RunLevel HighestView examples
Set operational behavior$settings = New-ScheduledTaskSettingsSet ` -ExecutionTimeLimit (New-TimeSpan -Hours 1) ` -StartWhenAvailableView examples
Compose a task object$task = New-ScheduledTask -Action $action -Trigger ` $trigger -Settings $settings -Description ` 'Nightly export'View examples
Register a taskRegister-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport' -InputObject $taskView examples
Start on demandStart-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport'View examples
Stop a running taskStop-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport'View examples
Disable triggersDisable-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport'View examples
Enable a taskEnable-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport'View examples
Export task XMLExport-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport' | Set-Content -LiteralPath '.\NightlyExport.xml' -Encoding UnicodeView examples
Remove with confirmationUnregister-ScheduledTask -TaskPath ` '\CmdMemo\' -TaskName 'NightlyExport' -ConfirmView examples

Scheduled tasks combine actions, triggers, principals, settings, and current runtime state. Inspect both the definition and recent execution information before changing a task, use explicit paths and executable arguments, and export important definitions before replacement or removal. Register tasks from an elevated session only when the chosen principal or folder requires it.

Step by step

Detailed examples

01

Identify a task by folder and name

TaskName is not globally unique because Task Scheduler organizes definitions under TaskPath folders. Always carry both values into later commands and keep the leading and trailing backslashes in a non-root path. Filter early rather than piping an ambiguous display name into a change command.

Find matching definitions without changing them
Get-ScheduledTask |
  Where-Object TaskName -like '*Export*' |
  Select-Object TaskPath, TaskName, State |
  Sort-Object TaskPath, TaskName
Back to quick reference ↑
02

Separate definition state from run history

Get-ScheduledTask returns actions, triggers, principal, settings, and current scheduler state. Get-ScheduledTaskInfo supplies last run, next run, missed runs, and the numeric last result. A successful launch does not prove the script produced the intended output, so correlate task history with application logs and artifacts.

Review a task and its recent result
$identity = @{ TaskPath = '\CmdMemo\'; TaskName = 'NightlyExport' }
$task = Get-ScheduledTask @identity
$info = Get-ScheduledTaskInfo @identity

$task | Select-Object TaskPath, TaskName, State, Author, Description
$task.Actions | Format-List Execute, Arguments, WorkingDirectory
$info | Select-Object LastRunTime, LastTaskResult, NextRunTime, NumberOfMissedRuns
Back to quick reference ↑
03

Compose and inspect actions and triggers before registration

An action separates the executable from its argument string. Use a fully qualified script path and quote embedded paths according to the launched executable's parsing rules. Triggers use the machine's local scheduling context. New-ScheduledTask creates an in-memory definition, making it possible to inspect the assembled object before registration changes system state.

Build a daily PowerShell task definition
$action = New-ScheduledTaskAction `
  -Execute 'C:\Program Files\PowerShell\7\pwsh.exe' `
  -Argument '-NoLogo -NoProfile -NonInteractive -File "C:\Scripts\Export.ps1"' `
  -WorkingDirectory 'C:\Scripts'

$trigger = New-ScheduledTaskTrigger -Daily -At '02:00'
$settings = New-ScheduledTaskSettingsSet `
  -StartWhenAvailable `
  -ExecutionTimeLimit (New-TimeSpan -Hours 1)

$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings -Description 'Nightly export'
$task | Format-List *
Back to quick reference ↑
04

Choose the least-privileged execution context

The principal determines identity, logon type, and elevation. SYSTEM is highly privileged and should be reserved for work that truly requires it. Interactive-token tasks require the user to be logged on; password and service-account modes have different credential and network-access behavior. Test access to scripts, working directories, network resources, and secrets under the actual identity.

Define a built-in service principal
$principal = New-ScheduledTaskPrincipal `
  -UserId 'NT AUTHORITY\SYSTEM' `
  -LogonType ServiceAccount `
  -RunLevel Highest

$principal | Select-Object UserId, LogonType, RunLevel

Note: Use a less-privileged service identity when the action does not need SYSTEM rights.

Back to quick reference ↑
05

Export the old definition before registration or replacement

Register-ScheduledTask commits a definition and can replace an existing task when Force is supplied. Because registration may change credentials, permissions, and runtime behavior, resolve the exact identity, export any existing definition, inspect the new task object, and record the intended principal before proceeding. Do not put plaintext passwords in scripts or shell history.

Back up and register an inspected definition
$identity = @{ TaskPath = '\CmdMemo\'; TaskName = 'NightlyExport' }
$existing = Get-ScheduledTask @identity -ErrorAction SilentlyContinue
if ($existing) {
  Export-ScheduledTask @identity |
    Set-Content -LiteralPath '.\NightlyExport.before.xml' -Encoding Unicode
}

$task | Format-List Actions, Triggers, Principal, Settings
Register-ScheduledTask @identity -InputObject $task

Note: Registration changes Task Scheduler. Run it only after reviewing the resolved identity and in-memory definition.

Back to quick reference ↑
06

Operate a registered task without rewriting it

Start-ScheduledTask requests an on-demand run and returns before the action necessarily completes. Poll state and runtime information or inspect the action's logs for completion. Disable retains a recoverable definition while preventing trigger activation; stop can interrupt application work, so understand its consistency and retry behavior first.

Run once, inspect, and disable if necessary
$identity = @{ TaskPath = '\CmdMemo\'; TaskName = 'NightlyExport' }
Start-ScheduledTask @identity
Get-ScheduledTask @identity | Select-Object TaskName, State
Get-ScheduledTaskInfo @identity | Select-Object LastRunTime, LastTaskResult

# Reversible containment when future triggers must pause:
Disable-ScheduledTask @identity
Back to quick reference ↑
07

Preserve recovery material before deletion

Export-ScheduledTask returns XML that can be reviewed and imported later, though credentials are not exported. Store the file in an access-controlled location and verify it is non-empty. Unregister deletes the definition but does not delete scripts or outputs launched by it; use confirmation and the exact task path.

Export, verify, then request confirmed removal
$identity = @{ TaskPath = '\CmdMemo\'; TaskName = 'NightlyExport' }
$backup = '.\NightlyExport.xml'
Export-ScheduledTask @identity | Set-Content -LiteralPath $backup -Encoding Unicode
Get-Item -LiteralPath $backup | Select-Object FullName, Length

Unregister-ScheduledTask @identity -Confirm

Note: The final command is destructive and prompts before removing the registered definition.

Back to quick reference ↑

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. MicrosoftScheduledTasks Modulelearn.microsoft.com
  2. MicrosoftRegister-ScheduledTasklearn.microsoft.com
  3. MicrosoftNew-ScheduledTaskActionlearn.microsoft.com
  4. MicrosoftNew-ScheduledTaskTriggerlearn.microsoft.com
  5. MicrosoftGet-ScheduledTaskInfolearn.microsoft.com

Help us improve

Found a typo or missing example?

Tell us what would make this cheat sheet clearer, more complete, or more useful.

Share feedback