Still unable to hand exit code to SCCM

Hello,

I posted this question a while back. How do I get the script to hand a specific exit code?

I understand that I need to use Exit-Script -ExitCode 1641 but I’m unable to determine where to place that in the script. I was told to “read the manual” in a previous post. I downloaded the manual and I’m searching on exit codes but not finding what I’m looking for. With a deadline I don’t have enough time to read the entire manual when a quick search turns up nothing.

  1. What section can I find this in?
  2. Where do I place Exit-Script -ExitCode 1618

Thank you!

We were launching PSADT with a CMD and the CMD was throwing the exit code away until will fiddled with it.

How are you launching PSADT’s ps1 file from SCCM?

Hi!

From SCCM I’m launching with the following command:

Powershell.exe -ExecutionPolicy ByPass -File D:\ITOnly\Office-16.0.14326.21018\Deploy-Application.ps1

I did find the Exit-Script piece in the PDF. Unfortunately, I’m still unable to determine where to place it in the deploy application script. It looks like it might be here?

}
##*===============================================
##* END SCRIPT BODY
##*===============================================

## Call the Exit-Script function to perform final cleanup operations
Exit-Script -ExitCode $mainExitCode

}
Catch {
[int32]$mainExitCode = 60001
[string]$mainErrorMessage = “$(Resolve-Error)”
Write-Log -Message $mainErrorMessage -Severity 3 -Source $deployAppScriptFriendlyName
Show-DialogBox -Text $mainErrorMessage -Icon ‘Stop’
Exit-Script -ExitCode $mainExitCode
}

That looks fine.

Not sure why it’s not working with SCCM.
Either try to find an example for SCCM launching powershell.exe
or
try to launch a simple PS1 script that returns an exitcode.

Perhaps this will help? You start your post mentioning 1641 (hard reboot code), but then further down 1618. As far as passing through the reboot exit codes (1641 or 3010) to SCCM is concerned, make sure you use -AllowRebootPassThru on your SCCM command line.

I have these lines in my template, commented-out, so I can choose one or the other if/when I need them. They sit in the post-install (or post-uninstall) section:

<# For SCCM to manage the restart, use the command line: "Deploy-Application.exe [Install/Uninstall] -AllowRebootPassThru" #>
# [int32]$mainExitCode = 3010  #Soft Reboot
# [int32]$mainExitCode = 1641  #Hard Reboot
1 Like