Skip to content

Instantly share code, notes, and snippets.

@MSAdministrator
Created May 21, 2016 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MSAdministrator/dbe6748096c398edd3854fa348c92602 to your computer and use it in GitHub Desktop.
Save MSAdministrator/dbe6748096c398edd3854fa348c92602 to your computer and use it in GitHub Desktop.
Get-MSIProperties
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
function Get-MSIProperties
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true)]
$MSI,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true)]
$Table,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true)]
$Property
)
Begin
{
Update-TypeData -AppendPath '$PSCriptRoot\comObject.types.ps1xml'
# A quick check to see if the file exist
if(!(Test-Path $MSI))
{
throw "Could not find " + $MSI
}
# Create an empty hashtable to store properties in
$msiProps = @{}
}
Process
{
# Creating WI object and load MSI database
$wiObject = New-Object -com WindowsInstaller.Installer
$wiDatabase = $wiObject.InvokeMethod("OpenDatabase", (Resolve-Path $MSI).Path, 0)
# Open the Property-view
$view = $wiDatabase.InvokeMethod("OpenView", "SELECT Value FROM $Table WHERE Name = '$Property'")
$view.InvokeMethod("Execute")
# Loop thru the table
$r = $view.InvokeMethod("Fetch")
while($r -ne $null)
{
# Add property and value to hash table
$msiProps[$r.InvokeParamProperty("StringData",1)] = $r.InvokeParamProperty("StringData",2)
# Fetch the next row
$r = $view.InvokeMethod("Fetch")
}
}
End
{
$view.InvokeMethod("Close")
# Return the hash table
return $msiProps
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment