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

Summary

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

The following is an example of using PowerShell to retrieve info from an .msi:

$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
Last update:
‎Jan 31, 2023 05:27 PM
Updated by:
Contributors