Failure signals
PowerShell scripts that report success for work that didn't happen. Each article asks the same question: what did this command tell you when it failed?
3 parts · 3 published

- Start here
Task Scheduler Falsely Reports Success for a PowerShell Script That Works Manually
Task Scheduler records the exit code of powershell.exe, not whether the script worked, so a script that hit an error and carried on is recorded as a success.
Why $LASTEXITCODE Doesn't Work the Way You Expect in PowerShell
Cmdlets never set LASTEXITCODE, so after a failed cmdlet it still holds whatever the last native program returned, often zero.
PowerShell -File vs. -Command: Which Exit Code Does the Caller Get?
Under -File the caller receives the exit code your script chose; under -Command, any script code other than 0 or 1 reaches the caller as 1.