File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,15 @@ function Install-FromExe {
4646 Write-Information - MessageData (' Installing {0} ...' -f $name ) - InformationAction Continue ;
4747 Write-Information - MessageData (' {0} {1}' -f $installerPath , ($options -join ' ' )) - InformationAction Continue ;
4848
49- Start-Process $installerPath - Wait - ArgumentList $options ;
49+ # According to https://stackoverflow.com/a/23797762 caching the handle is required to get ExitCode
50+ $process = Start-Process $installerPath - PassThru - ArgumentList $options ;
51+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUserDeclaredVarsMoreThanAssignments' , ' ' , Scope= ' Function' )]
52+ $handle = $process.Handle ;
53+ $process.WaitForExit ();
54+
55+ if ($process.ExitCode -ne 0 ) {
56+ Write-Error (' {0} installer failed with exit code {1}' -f $name , $process.ExitCode ) - ErrorAction Stop;
57+ }
5058
5159 # Update path
5260 Update-ScriptPath ;
Original file line number Diff line number Diff line change @@ -49,7 +49,15 @@ function Install-FromMsi {
4949 Write-Information - MessageData (' Installing {0} ...' -f $name ) - InformationAction Continue ;
5050 Write-Information - MessageData (' msiexec {0}' -f ($msiArgs -join ' ' )) - InformationAction Continue ;
5151
52- Start-Process msiexec - Wait - ArgumentList $msiArgs ;
52+ # According to https://stackoverflow.com/a/23797762 caching the handle is required to get ExitCode
53+ $process = Start-Process msiexec - PassThru - ArgumentList $msiArgs ;
54+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUserDeclaredVarsMoreThanAssignments' , ' ' , Scope= ' Function' )]
55+ $handle = $process.Handle ;
56+ $process.WaitForExit ();
57+
58+ if ($process.ExitCode -ne 0 ) {
59+ Write-Error (' {0} installer failed with exit code {1}' -f $name , $process.ExitCode ) - ErrorAction Stop;
60+ }
5361
5462 # Update path
5563 Update-ScriptPath ;
You can’t perform that action at this time.
0 commit comments