cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use Powershell to retrieve info from an .msi.

How to use Powershell to retrieve info from an .msi.

Synopsis:

You may want to read info from an existing .msi at times. This can be done with powershell.

 

Description:

The powershell may use a COM Windows installer object. Open the .MSI as a database, use a view to execute a query and fetch the data.

Below is an example of powershell querying the shortcut table of an .msi for values.

Other tables can be queried by changing the select statement in line:
$ShortcutsView = $MSI.OpenView("select * from Shortcut")

 

Column values can be retrieved from other columns by changing number value in the line:

Write-Output (Get-Property $Shortcuts StringData 1)

 

Example:

$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer

function Get-Property ($Object, $PropertyName, [object[]]$ArgumentList) {
return $Object.GetType().InvokeMember($PropertyName, 'Public, Instance, GetProperty', $null, $Object, $ArgumentList)
}

$MSI = $windowsInstaller.OpenDatabase("C:\InstallShield 2019 Projects\My Project Name-1\Product Configuration 1\Release 1\DiskImages\DISK1\My Project Name-1.msi", 0)

$ShortcutsView = $MSI.OpenView("select * from Shortcut")
$ShortcutsView.Execute()

$Shortcuts = $ShortcutsView.Fetch()

write-host "First 5 fields of Shortcut table" -ForegroundColor Green
if ($Shortcuts) {
Write-Output (Get-Property $Shortcuts StringData 1)
Write-Output (Get-Property $Shortcuts StringData 2)
Write-Output (Get-Property $Shortcuts StringData 3)
Write-Output (Get-Property $Shortcuts StringData 4)
Write-Output (Get-Property $Shortcuts StringData 5)
}


$ShortcutsView.Close()

$MSI.Commit()

$MSI = $null

[system.gc]::Collect()
[System.gc]::waitforpendingfinalizers()

 

Additional Information:
Here is a link to documentation on the COM Windows installer object.

https://docs.microsoft.com/en-us/windows/win32/msi/installer-object

Labels (1)
Was this article helpful? Yes No
No ratings
Version history
Revision #:
3 of 3
Last update:
‎Jun 03, 2020 01:25 PM
Updated by:
 
Contributors