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
2 Likes

Hello. I don’t have these entries in my Deploy-Aplication.ps1.

Does anyone have a clear and concise answer for this question?

We know it’s not in Deploy-Aplication.ps1.
That’s why we are telling you to try to add it.

$AllowRebootPassThru = $true	#Force Exit-Script to allow 1641 or 3010 to reach SCCM
Exit-Script -ExitCode 1618

I guessing you’d want it after everything is installed so I suggest in the POST-INSTALLATION section of Deploy-Aplication.ps1

1 Like

Hello all,

I tried the post installation section but the exit code still came out as 0. I find it interesting that no one in this community can determine where to place a line to hand off a specific exit code. I’m not an expert in Powershell so I’m not the best judge of where to place this.

Is there anyone in the community who knows where to place a line to force a specific exit code?

If you are having this much trouble maybe post SOME of the code you are trying to use.
Don’t post the whole thing. Only the relevant sections like INSTALLATION.
Make sure to include #comments in the code so that we can see what you are trying to do.
and try to use the </> Preformatted text tool to post as code instead of text.

This is the code I am using:

Exit-Script -ExitCode 1618

That’s it. The problem is that I am unable to determine the last line in the script that is run (it’s not the line at the bottom of the script). If there is a variable to change - I don’t know what or where it is.

At the end of the script there is this section. I’ve tried changing $mainExitCode to the exit code I want but it still did not come back with the code I specify. Does anyone know where to put a line in this script to put a line to exit with a specific code?

</
##===============================================
##
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
}/>

I think exitcodes like 1618 should make it to SCCM but JIC (b/c of your situation) I’d add $AllowRebootPassThru = $true before your line. And because you can’t be certain of what is going on, add some Write-Log lines before and after anything that should and should not be running.

Write-log "Greydog67: Exiting with 1618"
$AllowRebootPassThru = $true
Exit-Script -ExitCode 1618
Write-log "Greydog67: Should not see this after Exiting with 1618"

.
And since you think the Exit-Script -ExitCode $mainExitCode line is coming into play, do this:

Write-log "Greydog67: Should not see this Exiting with `$mainExitCode"
## Call the Exit-Script function to perform final cleanup operations
Exit-Script -ExitCode $mainExitCode
Write-log " Greydog67: Should not see this after Exiting with `$mainExitCode"

Once we can determine that your Script is working as expected, you can focus on what happens to the exitcode after the script is done. (Divide and conquer!)

Awesome! I’ll try this out!