Calling PSADT Execute-Process and how to handle Exit Code

Hi @ll,

Right now I need some experience from the community on how to use the Execute Process function to start an external program during an installation or not to use it. From my personal background I would never start an external program without handling the exit code, e.g.

$ ret = Execute-Process -Path “setup.exe” -Parameter “/ s” -IgnoreExitCode “1,2,3”

if ($ ret -nq 0)
{
Exit script -Exitcode $ ret
}

but I’ve seen a couple of examples without the “Error Handling Logic” so I’m not sure if this (my style) is a good or normal way to solve this problem in PSADT

any kind of suggestion (also hidden Tips and Tricks) are very welcomed

thx

K.

Try adding -PassThru

$ret = Execute-Process -Path “setup.exe” -Parameter “/ s” -IgnoreExitCode “1,2,3” -PassThru

if ($ret.Exitcode  -ne 0)
{
Exit script -Exitcode $ret.Exitcode 
}

Hello thx for the. :wink: Typo in my example but the main question behind it is. is it necessary to check the exit code yes / no and if not why not

the whole section of deploy-application.ps1 is in a try /catch grouping. in your original example, ignoreexitcode would simple return a 0 as well for exitcodes 1,2, or 3 which would allow the script to continue. By default it will error out otherwise. The main “try” is right after the parameter section and the catch is at the bottom of the script.

In your example, if you wanted to handle that particular program separately and do extra work depending of success or failure, you could add a -continueonerror line and then use your additional logic block.

you could also wrap it in an additional try/catch block if necessary. However it will return failures by default.