forked from adbertram/Random-PowerShell-Work
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Get-MSIDatabaseProperties.ps1
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<# | ||
.SYNOPSIS | ||
This function retrieves properties from a Windows Installer MSI database. | ||
.DESCRIPTION | ||
This function uses the WindowInstaller COM object to pull all values 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 | ||
} | ||
|
||
process { | ||
try { | ||
$database = $com_object.GetType().InvokeMember( | ||
"OpenDatabase", | ||
"InvokeMethod", | ||
$Null, | ||
$com_object, | ||
@($FilePath.FullName, 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) { | ||
$msi_props[$record.GetType().InvokeMember("StringData", "GetProperty", $Null, $record, 1)] = $record.GetType().InvokeMember("StringData", "GetProperty", $Null, $record, 2) | ||
$record = $View.GetType().InvokeMember( | ||
"Fetch", | ||
"InvokeMethod", | ||
$Null, | ||
$View, | ||
$Null | ||
) | ||
} | ||
|
||
$msi_props | ||
|
||
} catch { | ||
throw "Failed to get MSI file properties the error was: {0}." -f $_ | ||
} | ||
} |