Is there a possibility to retreive the MSI product code out of a MSI file without installing it with PowerShell? I want to compare the product code of a MSI file with the MSI codes installed on a maschine to find out if the file was installed in the past.
Asked
Active
Viewed 1.9k times
5
-
[List of free tools you can used to view MSI files down the page here](https://stackoverflow.com/questions/48482545/how-can-i-compare-the-content-of-two-or-more-msi-files) (Orca, SuperOrca, etc...). The ProductCode can be found in the **`Property table`** once you have a tool capable of reading MSI files. And you can [find the product code for installed MSI setups](https://stackoverflow.com/q/29937568/129130). – Stein Åsmul Dec 26 '18 at 00:10
2 Answers
8
Here is a script that reads the product code based on [this article][1]:
$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.
[1]: http://www.scconfigmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/

David Gardiner
- 16,892
- 20
- 80
- 117

Martin Brandl
- 56,134
- 13
- 133
- 172
-
1Thanks! Unfortunately, you need the whole script code from the article, the extract is not working like this. But thanks! This solved the problem! – Aug 10 '15 at 13:17
-
1Replace "$WindowsInstaller" with "$comObjWI" and the extract will work – Jonathan H. Jan 25 '17 at 12:54
-
I think you need to remove the space between `$comObjWI` and `.getType()` on the 3rd line of code – Tim Feb 14 '20 at 12:45
6
A shorter way to get the ProductCode from a MSI package:
Get-AppLockerFileInformation -Path "C:\PathTo\my.msi" | select -ExpandProperty Publisher | Select BinaryName

Christophe
- 444
- 3
- 5
-
-
Sorry, I forgot to say that it does not work if your MSI is not digitally signed. – Christophe Jun 07 '22 at 15:51