Execute MSI with PowerShell and return the MSI exit code

I had the need to execute a MSI and get the script to return the exit code for a MSI installation. This is the script that I came up with.

    $filePath = ".\Adobe Flash Player (IE) 10.3.msi"
    $processSInput = New-Object System.Diagnostics.processSInput
    $processSInput.FileName = "$FilePath"
    $processSInput.Arguments = "/qn"
    $process = [System.Diagnostics.Process]::Start($processSInput)
    $exitCode = $process.ExitCode
    Write-Host "Exit Code: $exitCode"
    Write-Host "Something went wrong"


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.