Reputation: 7249
How can I get the return status of a command ran, while outputting any messages to out-null.
Right now I have
{command} | out-null
I would like to get the return status $?
of that command though. Anyway to do that?
Thanks
Upvotes: 1
Views: 786
Reputation: 407
exit $LastExitCode
You will get above return code on windows CLI using echo %errorlevel%. You can also return custom error code like this - exit 84
Upvotes: 0
Reputation: 3419
As requested, here's my comment as an answer... I'm guessing $LastExitCode will still hold the exit code; as a rule of thumb use $? for CMDLets and $LastExitCode for external apps.
Upvotes: 1