$PSNativeCommandUseErrorActionPreference
noun
say it: “PEE-ES NAY-tiv kuh-MAND yooz ER-er AK-shun PREF-er-ens” /ˌpiˈɛs ˈneɪtɪv kəˈmænd juz ˈɛrɚ ˈækʃən ˈprɛfərəns/
A PowerShell 7.4 and later setting that, when turned on, makes a program's failing exit code count as an error the script can stop on.
What does $PSNativeCommandUseErrorActionPreference do?
A program that fails doesn't stop a script on its own, even with $ErrorActionPreference = 'Stop', because it reports through its exit code. Set $PSNativeCommandUseErrorActionPreference to $true and any exit code but 0 counts as an error, so the script stops at the program's own line and try and catch can catch it.
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
git tag 'v1.2.0' # the tag already exists: exit code 128 stops the script
In a sentence
- “Sam added $PSNativeCommandUseErrorActionPreference under the line that sets Stop.”
- “With $PSNativeCommandUseErrorActionPreference set to $true, the failed git tag stopped the release.”
Level: Freelancer · More PowerShell terms at this level
Updated