Use this when a scheduled task's program or script doesn't run correctly.
Actions
Task actions define what a scheduled task does, usually start a program with arguments and a working directory, such as powershell.exe -File script.ps1. A task can run several actions in order.
1. (Get-ScheduledTask <name>).Actions — Execute, Arguments, WorkingDirectory.
2. Full paths; quote paths with spaces.
3. PowerShell: powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\x.ps1".
4. Exit code appears as LastTaskResult.
5. Log output to a file.
action starts program with arguments in the start-in folder → exits with a code
Context & applicabilityCommon mistakes · platform/version boundaries
- PowerShell scripts run without
-NoProfile -ExecutionPolicy Bypass -File, failing on policy or profiles. - Missing "Start in" folder for scripts with relative paths.
- Task running as SYSTEM accessing network shares (uses the computer account).
- Output not logged, so failures are invisible — redirect to a log file or use
Start-Transcript.
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 Checks Verify boundary
Get-ScheduledTaskInfo -TaskName NightlyJob | Select LastRunTime,LastTaskResult,NextRunTime
schtasks /query /tn NightlyJob /v /fo list
LastTaskResult 0 = success, 0x41301 = running, 0x1 = script error. Enable task history in Task Scheduler for event details (Microsoft-Windows-TaskScheduler/Operational).
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 full paths for programs and scripts.
- Arguments go in their own field.
- Set the working directory ('Start in').
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
Writing actions
- Use full paths to programs and scripts; the working directory defaults to
C:\Windows\System32. - PowerShell:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\scripts\job.ps1(signed scripts preferred). - Exit codes appear as Last Run Result (0x0 = success, 0x1 = general failure in the script).
- Run as a dedicated account or gMSA with least privilege, not a personal admin account.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Task actions run programs ("Start a program"; e-mail and message actions are deprecated). Run PowerShell scripts with explicit arguments:
program: C:\Program Files\PowerShell\7\pwsh.exe
arguments: -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "C:\Scripts\report.ps1" -Days 7
start in: C:\Scripts
Set "Start in" so relative paths work, log output from the script itself (tasks have no console), and return non-zero exit codes on failure so Last Run Result reflects errors.
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 → Actions. 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%