Created
May 21, 2016 04:09
-
-
Save MSAdministrator/dbe6748096c398edd3854fa348c92602 to your computer and use it in GitHub Desktop.
Get-MSIProperties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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