The essentials
Quick reference
One focused task per row. Jump to the related section for complete, working examples.
| Use | Syntax | Examples |
|---|---|---|
| List tasks | Get-ScheduledTask | Sort-Object TaskPath, TaskName | View examples |
| Get one exact task | Get-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Inspect runtime information | Get-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 -AtStartup | View examples |
| Run as a service account | $principal = New-ScheduledTaskPrincipal -UserId `
'NT AUTHORITY\SYSTEM' -LogonType ServiceAccount `
-RunLevel Highest | View examples |
| Set operational behavior | $settings = New-ScheduledTaskSettingsSet `
-ExecutionTimeLimit (New-TimeSpan -Hours 1) `
-StartWhenAvailable | View examples |
| Compose a task object | $task = New-ScheduledTask -Action $action -Trigger `
$trigger -Settings $settings -Description `
'Nightly export' | View examples |
| Register a task | Register-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' -InputObject $task | View examples |
| Start on demand | Start-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Stop a running task | Stop-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Disable triggers | Disable-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Enable a task | Enable-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Export task XML | Export-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | Set-Content -LiteralPath '.\NightlyExport.xml' -Encoding Unicode | View examples |
| Remove with confirmation | Unregister-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' -Confirm | View 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
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.
Get-ScheduledTask |
Where-Object TaskName -like '*Export*' |
Select-Object TaskPath, TaskName, State |
Sort-Object TaskPath, TaskName 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.
$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 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.
$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 * 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.
$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.
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.
$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.
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.
$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 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.
$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.
Sources and further reading
References
Authoritative documentation used to verify and expand this cheat sheet.
Help us improve
Found a typo or missing example?
Tell us what would make this cheat sheet clearer, more complete, or more useful.



