4th March 2019
Extract productcode from MSI
Here is a script you can use to extract productcode from msi-file
it´s raw…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
param( [Parameter(ValueFromPipeline = $true,HelpMessage = 'Enter CSV path')] [String[]]$Path = $null ) if($Path -eq $null) { Add-Type -AssemblyName System.Windows.Forms $Dialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog $Dialog.InitialDirectory = "$InitialDirectory" $Dialog.Title = 'Select MSI File' $Dialog.Filter = 'MSI File|*.MSI' $Dialog.Multiselect = $true $Result = $Dialog.ShowDialog() if($Result -eq 'OK') { Try { $Path = $Dialog.FileNames } Catch { $Path = $null Break } } else { #Shows upon cancellation of Save Menu Write-Host -ForegroundColor Yellow -Object 'Notice: No file(s) selected.' Break } } $Path = $Dialog.FileName $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 |