How do I negate the exit code of an executable in powershell? I would like my script to succeed if an executable terminated with a non-zero exit code, or fail if the executable terminated with a zero exit code.
I tried the following ! (...)
and it prints True
, which sounds promising, however it also makes the script fail with exit code 1.
! (program.exe) # I want this line to fail if program.exe returns 0
Output:
True
Error: Process completed with exit code 1.
Note that I'm just interested in checking the exit code of the executable. If the executable fails for other reasons (e.g. missing libraries) then it's fine for the script to fail.
This question has some similarities to this question for -nix systems. However, I'm writing a powershell script to be run on Windows 10.