Thursday, November 8, 2018

$LASTEXITCODE


$LASTEXITCODE is a preexisting variable which takes on the exit / error code of a command.

In this snippet powershell calls the vbscript items and adds the exit codes together to produce a final exit code total

$LASTEXITCODE = 0

$ErrorCode = $null

$Install1 = "cscript .\inst1.vbs"
$Install2 = "cscript .\inst2.vbs"

Invoke-Expression $Install1

    $ErrorCode += $LASTEXITCODE

Invoke-Expression $Install2

    $ErrorCode += $LASTEXITCODE

$ErrorCode
exit $ErrorCode