I'm using an SCCM 2012 application deployment to install software. The specific install type is scripted installer as SCCM kept failing for exe validation errors. The script is powershell and successfully installs the software even when executed by SCCM.
The problem is that SCCM only sees the return of 0 from the completion from the script. I've tried write-host
, return
, write-output
, and just a line item with the code for a soft reboot. None of them seem to be read by SCCM as the app execution log captures a return of 0.
How do you output return codes from powershell so that SCCM can interpret them?
There is a known problem with powershell exit codes (see the end of this answer) that can manifest when using powershell installation scripts with SCCM. To workaround the problem, I take two measures:
powershell.exe
explicitly.[System.Environment]::Exit()
.With these two measures, I haven't had a problem related to exit codes. That is a huge win because troubleshooting exit codes of installation scripts is a slow process because you have to wait for the SCCM client to invoke your script for each iteration of troubleshooting.
Here is what the batch file and powershell script look like:
Install-Application.bat
Install-Application.ps1
Why are exit codes unreliable when SCCM invokes powershell scripts directly?
Here is how we know exit codes are unreliable: