With BAT/CMD
script I can simply use \"msiexec /i
and then check %errorlevel%
for the result.
$LastExitCode
or
$?
depending on what you're after. The former is an integer, the latter just a boolean. Furthermore, $LastExitCode
is only populated for native programs being run, while $?
generally tells whether the last command run was successful or not – so it will also be set for cmdlets.
PS Home:\> cmd /c "echo foo"; $?,$LASTEXITCODE
foo
True
0
PS Home:\> cmd /c "ech foo"; $?,$LASTEXITCODE
'ech' is not recognized as an internal or external command,
operable program or batch file.
False
1