locked
Version Of multiple msi RRS feed

  • Question

  • Hi i need to know versions of the msi packages ,can anyone help me with this
    Thursday, September 6, 2018 5:33 AM

Answers

  • This question has been answered before on StackOverflow: https://stackoverflow.com/questions/8743122/how-do-i-find-the-msi-product-version-number-using-powershell. The Get-MsiDatabaseVersion function should do as you ask.

    From Andi Arismendi:

    function Get-MsiDatabaseVersion {
        param (
            [IO.FileInfo] $FilePath
        )
    
        try {
            $windowsInstaller = New-Object -com WindowsInstaller.Installer
    
            $database = $windowsInstaller.GetType().InvokeMember(
                    "OpenDatabase", "InvokeMethod", $Null, 
                    $windowsInstaller, @($FilePath.FullName, 0)
                )
    
            $q = "SELECT Value FROM Property WHERE Property = 'ProductVersion'"
            $View = $database.GetType().InvokeMember(
                    "OpenView", "InvokeMethod", $Null, $database, ($q)
                )
    
            $View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
    
            $record = $View.GetType().InvokeMember(
                    "Fetch", "InvokeMethod", $Null, $View, $Null
                )
    
            $productVersion = $record.GetType().InvokeMember(
                    "StringData", "GetProperty", $Null, $record, 1
                )
    
            $View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)
    
            return $productVersion
    
        } catch {
            throw "Failed to get MSI file version the error was: {0}." -f $_
        }
    }
    
    Get-MsiDatabaseVersion "C:\Installer.msi"

    • Marked as answer by Kranthi11 Thursday, September 6, 2018 5:44 AM
    Thursday, September 6, 2018 5:41 AM