Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created April 11, 2011 04:43
Show Gist options
  • Save jstangroome/913062 to your computer and use it in GitHub Desktop.
Save jstangroome/913062 to your computer and use it in GitHub Desktop.
Read the ProductVersion from a Windows Installer MSI file via PowerShell
function Get-MsiProductVersion {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[ValidateScript({$_ | Test-Path -PathType Leaf})]
[string]
$Path
)
function Get-Property ($Object, $PropertyName, [object[]]$ArgumentList) {
return $Object.GetType().InvokeMember($PropertyName, 'Public, Instance, GetProperty', $null, $Object, $ArgumentList)
}
function Invoke-Method ($Object, $MethodName, $ArgumentList) {
return $Object.GetType().InvokeMember($MethodName, 'Public, Instance, InvokeMethod', $null, $Object, $ArgumentList)
}
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
#http://msdn.microsoft.com/en-us/library/aa369432(v=vs.85).aspx
$msiOpenDatabaseModeReadOnly = 0
$Installer = New-Object -ComObject WindowsInstaller.Installer
$Database = Invoke-Method $Installer OpenDatabase @($Path, $msiOpenDatabaseModeReadOnly)
$View = Invoke-Method $Database OpenView @("SELECT Value FROM Property WHERE Property='ProductVersion'")
Invoke-Method $View Execute
$Record = Invoke-Method $View Fetch
if ($Record) {
Write-Output (Get-Property $Record StringData 1)
}
Invoke-Method $View Close @()
Remove-Variable -Name Record, View, Database, Installer
}
@Mobe1969
Copy link

Mobe1969 commented Dec 2, 2021

No worries @DoublNAT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment