-
Notifications
You must be signed in to change notification settings - Fork 5
Description
For the install, uninstall and update scripts, there is no explicit exit code returned to the spawning process. When these scripts are deployed via a RMM, the RMM can read the exit code to determine if the task executed successfully or not. This will require changes to the start-process lines as well as adding an exit command as the last line of the script.
Take the following line as an example:
Start-Process -FilePath $destination -ArgumentList "-s" -Wait
This should be changed to:
$Process = Start-Process -FilePath $destination -ArgumentList "-s" -Wait -NoNewWindow -PassThru
The NoNewWindow switch tells powershell not to spawn a separate process to run the program. This allows anything that might be written to the StdOut to be made available to the script output (not necessarily useful here but a good habit for writing scripts that will execute via a RMM). More importantly, the PassThru switch captures the process status and passes that back through to the $Process variable. This allows the referencing of the $Process variable to determine various things about the install/uninstall/updater process. The most important part here is the $Process.ExitCode value. This should be 0 if the installer was successful, and a non-zero value if the process encountered an error.
Lastly, the final line of the script should be:
exit $Process.ExitCode
This will pass the exit code value of the install/uninstall/update process as the value of the script itself. So if the program had an error, the RMM will get that value. If the exit code value is not explicitly defined, it will roll up from the end of the script and the last exit code generated by a command would be what is passed at the termination of the script. This can cause scripts not to terminate with an expected exit code
There are various places in the scripts where an exit command is sent in response to the installer failing to download or a token not being supplied to the script.
Write-Host "Downloading Zorus Deployment Agent..."
try
{
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($source, $destination)
}
catch
{
Write-Host "Failed to download installer. Exiting."
Exit
}
In these cases the exit command should have a non-zero value supplied to it. i.e.:
Write-Host "Downloading Zorus Deployment Agent..."
try
{
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($source, $destination)
}
catch
{
Write-Host "Failed to download installer. Exiting."
Exit 1
}
This will let the spawning process (most likely the RMM) see the script as failed rather than successful.