From 4914aada05d1101853b8468c1b41c3af430058fb Mon Sep 17 00:00:00 2001 From: Gabe Date: Tue, 5 Aug 2025 15:11:23 +0000 Subject: [PATCH] Upload files to "Get Scripts" --- ... Software Version from a MSI Installer.ps1 | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Get Scripts/Get Software Version from a MSI Installer.ps1 diff --git a/Get Scripts/Get Software Version from a MSI Installer.ps1 b/Get Scripts/Get Software Version from a MSI Installer.ps1 new file mode 100644 index 0000000..9c39f36 --- /dev/null +++ b/Get Scripts/Get Software Version from a MSI Installer.ps1 @@ -0,0 +1,21 @@ +param ( + [parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.IO.FileInfo] $MSIPATH +) +if (!(Test-Path $MSIPATH.FullName)) { + throw "File '{0}' does not exist" -f $MSIPATH.FullName +} +try { + $WindowsInstaller = New-Object -com WindowsInstaller.Installer + $Database = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $WindowsInstaller, @($MSIPATH.FullName, 0)) + $Query = "SELECT Value FROM Property WHERE Property = 'ProductVersion'" + $View = $database.GetType().InvokeMember("OpenView", "InvokeMethod", $Null, $Database, ($Query)) + $View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null) | Out-Null + $Record = $View.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $View, $Null ) + $Version = $Record.GetType().InvokeMember( "StringData", "GetProperty", $Null, $Record, 1 ) + return $Version +} +catch { + throw "Failed to get MSI file version: {0}." -f $_ +} \ No newline at end of file