A PowerShell job you tested by hand works perfectly, but Task Scheduler paints the last result red with 0x1 or 0x41303 and tells you nothing else. Both codes have precise meanings, and once you can read them the fix is short.
These are the two codes I see most often on Windows Server 2022 boxes running scheduled PowerShell 7.4 work. They are not random. 0x41303 is not really an error at all, and 0x1 almost always points at one of three specific mistakes in how the task action is defined. This decodes both and gives you the corrected action definition to paste in.
What the two codes actually mean
0x41303 is the HRESULT SCHED_S_TASK_HAS_NOT_RUN. It means the task has never run since it was created or since its last-result was reset. It is an informational status, not a failure. If a task you expected to have fired still shows 0x41303, the problem is that the trigger never fired — not that the script broke.
Free · 4 minutes
Is your engineering team shipping safely, or quietly accumulating risk?
Fourteen questions on how work gets from idea to production — cadence, testing, rollback, and the key-person risk in your delivery. Banded finding on screen, full sheet by email.
0x1 is ERROR_INVALID_FUNCTION, the most generic failure the scheduler can report. It means the action was attempted and something came back non-zero. In practice it is one of three things: the program path in the action is wrong, the arguments are malformed so pwsh.exe cannot find your script, or the script ran and exited with a non-zero code of its own. The scheduler cannot tell you which; you have to.
Fixing 0x41303: the task never fired
If a task sits on 0x41303 past the time it should have run, work through the reasons a trigger silently does nothing:
- The task is set to Run only when user is logged on and nobody is logged on. On a server this is the usual cause. Switch it to Run whether user is logged on or not.
- The trigger has a start date in the past with no recurrence, or a condition — Start the task only if the computer is on AC power, or an idle requirement — that is never met.
- The task, or the Task Scheduler service, is disabled.
To prove the task can run at all, right-click it and choose Run. If it executes on demand and the result changes, the definition is sound and the trigger is your problem. If running on demand also gives 0x1, skip ahead — the action is wrong. Choosing to run whether the user is logged on or not is also what forces the account to hold the Log on as a batch job right, which matters on a hardened box; more on that below.
Fixing 0x1: get the program and arguments split right
The single most common cause of 0x1 is cramming the whole command line into one box. The action has two distinct fields: Program/script and Add arguments. Only the executable goes in the first. Everything else — switches, the -File path, script parameters — goes in the second. Put pwsh.exe -File C:\Scripts\run.ps1 all in the program box and the scheduler tries to execute a file literally called that, and fails.
PowerShell 7 is pwsh.exe, not the Windows PowerShell 5.1 powershell.exe, and its default install path on Server 2022 is C:\Program Files\PowerShell\7\pwsh.exe. Use the full path; do not assume it is on the PATH of the service account. Because this is exactly the kind of definition that should live in source control rather than in a dialog box, I define the task itself in PowerShell:
# Program path goes in -Execute; everything else in -Argument.
$pwsh = 'C:\Program Files\PowerShell\7\pwsh.exe'
$script = 'C:\Scripts\Nightly Report\run.ps1' # path contains a space
# Note the backtick-escaped quotes: -File's path must be quoted because
# it contains a space, or pwsh sees two arguments and never finds the script.
$argline = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -File `"$script`" -Environment Prod"
$action = New-ScheduledTaskAction -Execute $pwsh -Argument $argline
$trigger = New-ScheduledTaskTrigger -Daily -At 02:00
$cred = Get-Credential -UserName 'CONTOSO\svc-reports' -Message 'Service account'
# -User/-Password sets 'run whether user is logged on or not' automatically.
Register-ScheduledTask -TaskName 'Nightly Report' -Action $action -Trigger $trigger `
-User $cred.UserName -Password $cred.GetNetworkCredential().Password -RunLevel Highest
The quoting is the part people get wrong. If your -File path contains a space and you do not quote it, pwsh receives the path as two arguments, fails to load the script, and exits non-zero — which the scheduler reports as 0x1. Inside a double-quoted PowerShell string the escape for an embedded quote is a backtick-quote, `", as above. -NoProfile stops a broken profile on the service account from tripping the run, and -NonInteractive ensures nothing blocks on a prompt no one will ever answer. I have written before on why I define scheduled tasks as PowerShell code instead of clicking through Task Scheduler, and this is precisely why: the dialog hides the quoting bug that the script makes obvious.
When the action is right but 0x1 persists
If pwsh.exe launches and your script runs but the result is still 0x1, the script is exiting non-zero. Task Scheduler surfaces the process exit code as the last result, and an uncaught terminating exception makes PowerShell exit with 1. That is not a scheduler fault — it is your job telling you it failed, through the only channel it has. The fix is to make the script report deliberately rather than by accident, and to leave a log the History tab will never show you:
# run.ps1 - make success and failure explicit for the scheduler.
$ErrorActionPreference = 'Stop'
$log = 'C:\Scripts\Nightly Report\last-run.log'
try {
# ... real work ...
"$(Get-Date -Format o) OK" | Out-File $log -Encoding utf8
exit 0
}
catch {
# Capture the reason; the scheduler only keeps the number.
"$(Get-Date -Format o) FAIL $($_.Exception.Message)" |
Out-File $log -Append -Encoding utf8
exit 1
}
Now a green result means the work genuinely finished and a red one leaves a message on disk saying why. If you call an external executable inside the script, check $LASTEXITCODE after it and decide for yourself whether that constitutes failure; PowerShell will not propagate it for you.
One more 0x1 trap on a hardened server: if the run-as account lacks the Log on as a batch job user right, the task cannot start under it. On a CIS-aligned Windows Server hardening baseline that right is tightly scoped, so add the service account explicitly under Local Security Policy → User Rights Assignment → Log on as a batch job, or via your GPO. This is worth confirming as part of a baseline Windows Server 2022 build before the first scheduled job goes on.
Read the evidence, not the icon
The last-result column is a single number; the History tab is the record. It is disabled by default — enable All Tasks History in the right-hand pane of Task Scheduler, then read the Action completed and Task Engine events for the run. They give you the exit code and the account the task actually ran under, which is frequently not the one you assumed. From a shell you can pull the same last-result without the console at all:
Get-ScheduledTask -TaskName 'Nightly Report' |
Get-ScheduledTaskInfo |
Select-Object TaskName, LastRunTime, LastTaskResult, NextRunTime
A LastTaskResult of 0 is success. 267011 is 0x41303 in decimal — the task has not run. 1 is 0x1. Decode the number, split the action correctly, quote the path, and make the script own its own exit code, and the red icon turns green with the actual cause named rather than guessed at.
Free interactive tool
Website compliance checklist
What your site has to do, based on what it actually does
Answer as much or as little as you like — the list builds as you go. Nothing is stored against your name and no email is required.
Everything that applies
Ordered by what to do first: legal requirements you can close quickly, then larger pieces of work, then what is expected rather than required. Not exhaustive, and not a legal audit.
Dated PDF, yours to keep or circulate.
Most technology problems are not technology problems. They are control problems.
The systems exist. The investment has been made. The question is whether leadership can understand, direct, evidence, and sustain what those systems produce. Find out where control exists — and where it only appears to.