How to pass exit codes to PSADK and SCCM

Hello,
I am new to this, sorry if it’s a stupid question.

I have a script that I am copying into PSADK pre-installation phase. I have made certain checks for if the script worked or not, if not it creates a log and exits.

But when deploying this via SCCM it says success even when it’s been a failure. How do I make PSADK exit with the right exit codes so SCCM understands it? Do I need to set a variable at the end of my script?

Hey,

You can use below function:
Exit-Script -ExitCode 1618

The script will get exit with 1618 parameter and the execution will stop immediately. The same error will be passed to SCCM and of Course you can use your own error code in place of 1618.

-Peace