Use this when scheduling PowerShell scripts.
Scheduled Jobs · PowerShell Automation
PowerShell scheduled jobs (Register-ScheduledJob) or scheduled tasks (Register-ScheduledTask) run scripts on a schedule; use a service account or gMSA and log output to a file.
1. Scheduled jobs/tasks run scripts on a schedule.
2. Prefer Task Scheduler with gMSA.
3. Log output.
4. Check LastTaskResult.
5. Avoid storing passwords in tasks.
schedule → task → script → result code
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 Verification path Verify boundary
Inspect definitions with Get-ScheduledJob, correlate them with Task Scheduler state, and review job instances/output after a run. Trigger a controlled test under the actual scheduled identity and verify target state after execution. Capture both scheduler history and PowerShell job output because either layer can fail independently.
Step 2 Common mistakes Narrow the fault
- Scheduled jobs running as users who leave.
Step 3 Where it fails Narrow the fault
Do not treat Scheduled Jobs as a cross-platform/current-PowerShell primitive. The scheduling service, Windows PowerShell 5.1 engine, job repository and target operation are distinct boundaries. Migration requires preserving identity, trigger semantics, credentials and output/retention behavior rather than only copying command text.
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.
- Use scheduled tasks for PowerShell scripts.
- Run as a service account or gMSA.
- Log output to a file.
Get-ScheduledJob— PS scheduled jobs (5.1)Get-ScheduledTask -TaskPath \Custom\— Task Scheduler tasksGet-ScheduledTaskInfo -TaskName <n>— last result
ReferenceWhy it matters1 section · depth on demand
In depth
PowerShell scheduled jobs and Windows scheduled tasks run scripts automatically. Scheduled jobs (Register-ScheduledJob, Windows PowerShell 5.1) store results as job objects; for PowerShell 7 and general use, scheduled tasks are the standard.
$a = New-ScheduledTaskAction -Execute 'pwsh.exe' -Argument '-NoProfile -NonInteractive -File C:\Automation\Sync-Netbox.ps1'
$t = New-ScheduledTaskTrigger -Once -At (Get-Date).Date.AddHours(1) -RepetitionInterval (New-TimeSpan -Minutes 30)
$p = New-ScheduledTaskPrincipal -UserId 'CORP\gmsa-netsync$' -LogonType Password
Register-ScheduledTask -TaskName 'NetBox sync' -Action $a -Trigger $t -Principal $p
Write logs to a file or the event log from the script itself (Start-Transcript or a logging function), since scheduled tasks capture no console output, and exit with meaningful codes so LastTaskResult reflects failures.
ReferenceImportant terms & boundaries1 section · depth on demand
PowerShell mechanics
Windows PowerShell Scheduled Jobs combine the PSScheduledJob module with Windows Task Scheduler: a scheduled-job definition persists trigger/options/credential metadata, Task Scheduler starts the work, and completed instances are represented as PowerShell jobs with stored results. The feature is a Windows PowerShell 5.1 compatibility surface and is not available as a compatible feature in PowerShell 6+.
ReferenceConfiguration & state1 section · depth on demand
Authoring and lifecycle
Use Scheduled Jobs only when Windows PowerShell 5.1 compatibility is an intentional requirement; for modern automation evaluate Task Scheduler directly or another scheduler/orchestrator. Record trigger, execution identity, working environment and output-retention settings. Do not assume an interactive user's profile, mapped drives or credentials exist in the scheduled context.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Review target identity, permissions and environment before mutation.
Register-ScheduledJob -Name DemoAudit -ScriptBlock { Get-Date } -Trigger (New-JobTrigger -Once -At (Get-Date).AddHours(1))Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/powershell/module/psscheduledjob/about/about_scheduled_jobs?view=powershell-5.1 · confidence 94%Quick lookup tables
Scheduled Jobs · PowerShell operational reference
Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.
| Boundary | Scheduled Jobs reference |
|---|---|
| Runtime identity | PowerShell edition/version + command/module source |
| Persistent intent | Script/module/config prerequisites under source control |
| Verification | Read-only discovery → execution evidence → independent target read-back |
| Output contract | Structured objects/streams before formatting |
| Failure boundary | Separate engine/binding from transport/API/native and target-state failures |
Deep reference
Healthy vs suspicious evidence
Output interpretation
A registered scheduled job can be enabled while its last run failed, and Task Scheduler can launch PowerShell successfully even when the script's business operation fails. Stored job output may differ from interactive formatting/environment. Correlate scheduler result codes, PowerShell errors and target-state read-back.