Skip to content

Instantly share code, notes, and snippets.

@martin77s
Created May 26, 2018 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin77s/11e20a3a0bbf61942ba39b52b6589567 to your computer and use it in GitHub Desktop.
Save martin77s/11e20a3a0bbf61942ba39b52b6589567 to your computer and use it in GitHub Desktop.
Get the product name, version and Id from an MSI installation package
function Get-MsiProductInformation {
param($Path)
$msis = Get-ChildItem -File -Path $Path -Filter '*.msi'
foreach($msi in $msis) {
$WI = New-Object -ComObject WindowsInstaller.Installer
$DB = $WI.GetType().InvokeMember("OpenDatabase","InvokeMethod", $Null, $WI, @($msi.FullName, 0))
$query = 'SELECT * FROM Property'
$View = $DB.GetType().InvokeMember("OpenView","InvokeMethod",$Null,$DB,($query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$Rec = $View.GetType().InvokeMember("Fetch","InvokeMethod",$Null,$View,$Null)
$props = @{}
while ($Rec -ne $null) {
$props[$rec.GetType().InvokeMember("StringData", "GetProperty", $Null, $rec, 1)] = $rec.GetType().InvokeMember("StringData", "GetProperty", $Null, $rec, 2)
$rec = $View.GetType().InvokeMember("Fetch","InvokeMethod",$Null,$View,$Null)
}
New-Object PSObject -Property @{
ProductName = $props.ProductName
ProductVersion = $props.ProductVersion
ProductCode = $props.ProductCode
}
}
}
# Example:
# Get-MsiProductInformation -Path C:\Installs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment