Run MsiExec from PowerShell and get Return Code

Skatterbrainz picture Skatterbrainz · Nov 8, 2010 · Viewed 60.3k times · Source

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?

Answer

ravikanth picture ravikanth · Nov 10, 2010

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