Search code examples
powershellreturn-valueexit-codewindows-installer

Run MsiExec from PowerShell and get Return Code


With BAT/CMD script I can simply use "msiexec /i <whatever.msi> /quiet /norestart" and then check %errorlevel% for the result.

With VBScript, using the Wscript.Shell object Run() method, I can get the result like this:

"result = oShell.Run("msiexec /i ...", 1, True)"

How can I do this with PowerShell?


Solution

  • I would wrap that up in Start-Process and use the ExitCode property of the resulting process object. For example

    (Start-Process -FilePath "msiexec.exe" -ArgumentList "<<whatever>>" -Wait -Passthru).ExitCode