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.
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
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
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.
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
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!)