Public/PsOsUtil.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

<############################################################################
 # Check for EXE results and throw exception on failure.
 # By default if Powershell runs an external exe it does not automatically
 # check the response code. Here we are saying if response to previous
 # command is non-zero throw exception
 ############################################################################>

Function Confirm-LastExitCode() {
    [int[]]$SuccessCodes = @(0)
    if ($SuccessCodes -notcontains $LastExitCode) {
        $msg = @"
EXE RETURNED EXIT CODE $LastExitCode
CALLSTACK:$(Get-PSCallStack | Out-String)
"@

        throw $msg
    }
}