Private/Powershell/PsOsUtil.ps1


<############################################################################
 # 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
    }
}