PowerShell: Get the MSI product code out of a MSI file without installing? PowerShell: Get the MSI product code out of a MSI file without installing? powershell powershell

PowerShell: Get the MSI product code out of a MSI file without installing?


Here is a script that reads the product code based on this article:

$path = "pathto.msi"$comObjWI = New-Object -ComObject WindowsInstaller.Installer$MSIDatabase = $comObjWI .GetType().InvokeMember("OpenDatabase","InvokeMethod",$Null,$comObjWI,@($Path,0))$Query = "SELECT Value FROM Property WHERE Property = 'ProductCode'"$View = $MSIDatabase.GetType().InvokeMember("OpenView","InvokeMethod",$null,$MSIDatabase,($Query))$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)$Record = $View.GetType().InvokeMember("Fetch","InvokeMethod",$null,$View,$null)$Value = $Record.GetType().InvokeMember("StringData","GetProperty",$null,$Record,1)

$Value now contains the product code.


A shorter way to get the ProductCode from a MSI package:

Get-AppLockerFileInformation -Path "C:\PathTo\my.msi" | select -ExpandProperty Publisher | Select BinaryName