Force a reboot after successful installation

I know I am probably over-looking this command in the toolkit but I have not been able to find the command to force a reboot after a successful installation.

I have seen some reference online to “Restart-Computer -Force” but I am not sure if that will still return a successful exit code in the logs.

What is the best practice to force the reboot in the script? I know that I can force it when using in SCCM, but I will be running this deploy-application.exe manually for now.

Thanks.

If you’re running it manually you could just create a CMD file as a wrapper, and trigger a restart after the script completes successfully.

Something like this:

@echo off
Deploy-Application.exe
if errorlevel 3010 (
shutdown -r -t 0
)

Just adjust the If statement or remove it completely. Using a wrapper allows the installation to complete fully and finalize logging and such.

Hope this helps

Show-InstallationRestartPrompt, has parameters for CountdownSeconds, CountdownNoHideSeconds and NoCountdown.

Thanks.

Wasn’t sure if the Show-InstallationRestartPrompt would be able to actually force a reboot on timeout. But if that works, surely that’s a better alternative.

In Deploy-Application.ps1 in the Post-installation phase include this as the last action. The script will reboot the machine and quit the script properly. If you create logs (see config XML) you can actually see when the reboot happend.

If (($mainExitCode -eq 0) -OR ($mainExitCode -eq 3010)) {
Show-InstallationRestartPrompt -NoCountdown
}

1 Like