Skip to content

Instantly share code, notes, and snippets.

@torutk
Last active March 12, 2016 02:52
Show Gist options
  • Save torutk/ce0e2f5231dde6ce4a0c to your computer and use it in GitHub Desktop.
Save torutk/ce0e2f5231dde6ce4a0c to your computer and use it in GitHub Desktop.
PoweShell Cmdlet to show properties of Windows Installer MSI file, such as ProductName, ProductVersion, ProductCode, UpgradeCode...
Function Get-MsiDatabaseProperties() {
<#
.SYNOPSIS
This function retrieves properties from a Windows Installer MSI database.
.DESCRIPTION
This function uses the WindowInstaller COM object to pull all value from
the Property table from a MSI
.EXAMPLE
Get-MsiDatabaseProperties 'MSI_PATH'
.PARAMETER FilePath
The path to the MSI you'd like to query
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='What is the path of the MSI you would like to query?')]
[IO.FileInfo[]]$FilePath
)
begin {
$com_object = New-Object -com WindowsInstaller.Installer
$fullname = $FilePath.FullName
write-host "FilePath = $FilePath", "FilePath.FullName = $fullname", "pwd = $pwd"
}
process {
$database = $com_object.GetType().InvokeMember(
"OpenDatabase",
"InvokeMethod",
$Null,
$com_object,
@((Resolve-Path $FilePath).Path, 0)
)
$query = "SELECT * FROM Property"
$View = $database.GetType().InvokeMember(
"OpenView",
"InvokeMethod",
$Null,
$database,
($query)
)
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$record = $View.GetType().InvokeMember(
"Fetch",
"InvokeMethod",
$Null,
$View,
$Null
)
$msi_props = @{}
while ($record -ne $null) {
$prop_name = $record.GetType().InvokeMember("StringData", "GetProperty", $Null, $record, 1)
$prop_value = $record.GetType().InvokeMember("StringData", "GetProperty", $Null, $record, 2)
$msi_props[$prop_name] = $prop_value
$record = $View.GetType().InvokeMember(
"Fetch",
"InvokeMethod",
$Null,
$View,
$Null
)
}
$msi_props
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment