-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-MsiFileInfo.ps1
40 lines (30 loc) · 1.11 KB
/
Get-MsiFileInfo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# TODO: Merge or replace with: https://github.com/itpro-tips/PowerShell-Toolbox/blob/master/Get-MSIFileInformation.ps1
Param (
[Parameter(Mandatory)][string]$FileName,
[Parameter()][ValidateSet("ProductVersion", "ProductCode")]
[string]$Property = "ProductVersion"
)
try {
$FullPath = (Resolve-Path $FileName).Path
$windowsInstaller = New-Object -com WindowsInstaller.Installer
$database = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase", "InvokeMethod", $Null,
$windowsInstaller, @($FullPath, 0)
)
$q = "SELECT Value FROM Property WHERE Property = '$Property'"
$View = $database.GetType().InvokeMember(
"OpenView", "InvokeMethod", $Null, $database, ($q)
)
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$record = $View.GetType().InvokeMember(
"Fetch", "InvokeMethod", $Null, $View, $Null
)
$msiFileInfo = $record.GetType().InvokeMember(
"StringData", "GetProperty", $Null, $record, 1
)
$View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)
return $msiFileInfo
}
catch {
throw "Failed to get MSI file info. The error was: {0}." -f $_
}