$cs.File_GetProductVersion
Description
Section titled “Description”Reads the ProductVersion from a file’s version resource. This is distinct from FileVersion (see $cs.File_GetFileVersion) — for example, several related files can share one ProductVersion while each having a unique FileVersion. Throws FileNotFoundException if filepath doesn’t exist.
Syntax
Section titled “Syntax”$cs.File_GetProductVersion(string filepath)
Parameters
Section titled “Parameters”filepath (String)
Section titled “filepath (String)”Full path of the file to retrieve the ProductVersion from.
Return value
Section titled “Return value”String containing the ProductVersion.
Example
Section titled “Example”$filepath = Join-Path ${env:ProgramFiles} "Mozilla Firefox\firefox.exe"if ($cs.File_ExistFile($filepath)){ $productVersion = $cs.File_GetProductVersion($filepath) $cs.Job_WriteLog("Installed product version: $productVersion")}Read a vendor EXE’s ProductVersion and record it in the registry, so it can be checked again later without re-reading the file ($global:Packageroot is removed by CapaInstaller after the package finishes running, so it isn’t a suitable place to persist values like this):
$vendorExe = Join-Path ${env:ProgramFiles(x86)} "Contoso\Suite\ContosoSuite.exe"if ($cs.File_ExistFile($vendorExe)){ $productVersion = $cs.File_GetProductVersion($vendorExe) $cs.Reg_SetString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'InstalledVersion', $productVersion) $cs.Job_WriteLog("Recorded installed product version $productVersion in the registry")}Confirm the ProductVersion of a freshly installed suite matches the version this PowerPack is meant to deploy:
$expectedProductVersion = "2024.3"$installedExe = Join-Path ${env:ProgramFiles(x86)} "Contoso\Suite\ContosoSuite.exe"$actualProductVersion = $cs.File_GetProductVersion($installedExe)if ($actualProductVersion -ne $expectedProductVersion){ $cs.Job_WriteLog("Warning: expected ProductVersion $expectedProductVersion but found $actualProductVersion")}