Sending an exit code to SCCM

Is it possible to send an exit code to SCCM. I am uninstalling and then reinstalling a newer version of Imprivata. If no one is logged in, I want it to send an Exit code of 3010 (reboot required) back to SCCM. I have it using the start-installationrestartprompt when someone is logged in and it brings up the restart prompt and works flawlessly.

It is returning an exit code of 0 when I need it to return an exit code of 3010 if know one is logged in.

Execute-MSI -Path “$dirFiles\x64\ImprivataAgent_x64.msi” -TRANSFORM “$dirFiles\x64\ImprivataAgent_x64.mst” -Passthru

The command line I am using in SCCM is:

“Deploy-Application.exe” -AllowRebootPassThru

Because the Exit Code is 0, the Reboot is not happening when I deploy through SCCM. How would I tell the script to send back error code 3010?



about 10 from the bottom Exit-Script -ExitCode 3010

This is because you are using the -passthru switch, this tells the script to ignore the result of the execution, you could capture it in an object for future use with something like:

[PSObject]$msiResult = Execute-MSI -Path “$dirFiles\x64\ImprivataAgent_x64.msi” -TRANSFORM “$dirFiles\x64\ImprivataAgent_x64.mst” -Passthru

Then you then test the previously captured exit code using the same object
If ($msiResult.ExitCode -eq 3010){Exit-Script -ExitCode 3010}

There is no reason to use a passthru switch parameter. Execute-MSI will return whatever it returns (3010 if it flags a reboot is required) and then that will be returned when the script exits by default. However, if you want the computer to always reboot after the app is installed, then control that in the deployment type in SCCM and tell it to always reboot, instead of relying on the MSI’s exit code.

Hi Pwetter. I am testing a script and i do not see that script return any exit codes from Execute-MSI.

The default deploy-application.ps1 script always returns 0 due to last command being Exit-Script -ExitCode $mainExitCode and $mainExitCode equal to 0…

Am i missing something? I tried calling only one Execute-MSI command where the MSI returns 3010 but the script never returns back to sccm…

I tried to find what global variable or returned variable from Execute-MSI but can not find.

Please advise i am using PSAppDeployToolkit_v3.8.0

This is really simple, If you want to reboot machine after application is done installing, after everything is done from msi or exe, you can just run one simple batch file with a single line.
EXIT /B 3010.
this will change return error on application install and this will show return code as 3010 always once application is done installing, now all you need to do is control this behavior via sccm, so you can refer articles and settings of psappdeploytoolkit doc file and check how to make sccm restart after app install.

I have recently done this in my env and it worked fine with sep install.

When it comes to reboot, add -AllowRebootPassThru as a parameter for Deploy-Application.exe in SCCM otherwise the toolkit will silence successful reboot exit codes and return 0. No need for additional batch files etc.

I should add that Execute functions have to return 3010 otherwise the toolkit has nothing to silence. If you want to make sure it is a 3010 exit code, put $mainExitCode = 3010 after the last Execute function.