PowerShell and Exit Codes
Today on the PowerShell email lists a question was brought up how to find the exit code of a program.
The solution:
$LastExitCode
Here is an example I found online:
function CheckExitCode {
param ([string]$failureMessage, [int[]]$successCodes = @(0), $finallyScript=$null)
$res = $successCodes -contains $LastExitCode
if ($res.Length -eq 0) {
write-error "ERROR CODE ${LastExitCode}: $failureMessage"
if ($finallyScript) {
"Executing finally:"
&$finallyScript
}
exit 1
}
}
Use like so:
tf checkin $file /noprompt
CheckExitCode "Checkin of $file" @(0) {tf undo $file /noprompt}
Trackbacks
No Trackbacks
Comments
No Comments