Use this when creating scheduled tasks that must run reliably as the right account with logging.
Scheduled Tasks
Scheduled tasks run actions automatically when triggered, as a chosen user or SYSTEM. Create them in Task Scheduler, with schtasks /create or Register-ScheduledTask.
1. List: Get-ScheduledTask | ? TaskPath -notlike '\Microsoft*'.
2. State Ready/Disabled/Running?
3. Create: Register-ScheduledTask with action, trigger and principal.
4. Run now: Start-ScheduledTask <name>.
5. Check result.
task registered → triggers, conditions, settings, principal, actions → runs
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Tasks running as users who later leave or change passwords.
- Tasks that run at logon on servers nobody logs on to.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Choose the account a task runs as.
- Triggers decide when it runs.
- Log the task's own output.
Get-ScheduledTask -TaskName <name> | fl *— task definitionGet-ScheduledTaskInfo -TaskName <name>— last run time and resultschtasks /query /tn <name> /v /fo list— details in CMDGet-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational -MaxEvents 30— task history (enable first)
ReferenceWhy it matters1 section · depth on demand
How it works
A scheduled task has three parts: one or more triggers (time, logon, startup, event ID, idle), actions (usually a program with arguments) and settings (run as which account, whether the user must be logged on, retry and stop rules). The Task Scheduler service (Schedule) runs it and records each run in Microsoft-Windows-TaskScheduler/Operational (enable history first). Exit code 0x0 means success; 0x41301 means still running.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Read a task's last result
PS C:\> Get-ScheduledTask -TaskName NightlyExport | Get-ScheduledTaskInfo
LastRunTime : 27-11-2026 02:00:01
LastTaskResult : 2147942402
NextRunTime : 28-11-2026 02:00:00
NumberOfMissedRuns : 0
PS C:\> '{0:X}' -f 2147942402
80070002
| LastTaskResult | Meaning |
|---|---|
| 0 | Success |
| 0x41301 (267009) | Task is currently running |
| 0x41303 | Task has not yet run |
| 0x80070002 | File not found — wrong path or working directory |
| 0x80070005 | Access denied — account lacks rights or "Log on as batch job" |
| 0x800710E0 | Operator or administrator refused the request — often "Run only when user is logged on" with nobody logged on |
| Program's own exit code | Whatever the script returned (for example 1) |
Create a task that behaves like a service job
$a = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -File D:\Jobs\export.ps1' -WorkingDirectory 'D:\Jobs'
$t = New-ScheduledTaskTrigger -Daily -At 02:00
$s = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 2) -RestartCount 2 -RestartInterval (New-TimeSpan -Minutes 10) -StartWhenAvailable
Register-ScheduledTask -TaskName NightlyExport -Action $a -Trigger $t -Settings $s -User 'CORP\gmsa-jobs$' -LogonType Password
A group managed service account (gmsa-jobs$) avoids stored passwords that expire. Set the working directory — scripts using relative paths otherwise run in C:\Windows\System32.
History and auditing
Task history is off by default: enable it (Task Scheduler → Enable All Tasks History, or wevtutil set-log Microsoft-Windows-TaskScheduler/Operational /enabled:true). Event 100 (started), 102 (completed), 201 (action completed with return code) and 103/101 (failed) then show the run.
Security review
Tasks run with stored credentials or as SYSTEM are a persistence technique for attackers. schtasks /query /fo LIST /v exports all tasks with their run-as account and actions for review.
*The scheduled task timestamps and result codes above are illustrative examples, not captured from a lab or production system.*
Commands
Get-ScheduledTask | Where State -ne Disabled | Select TaskPath,TaskName,State
schtasks /query /fo LIST /v /tn \MyTask
Start-ScheduledTask -TaskName MyTask
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Task Scheduler → Scheduled Tasks. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page · confidence 94%