Skip to content

$cs.File_GetProductVersion

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, and throws an error if the file has no version information. The value is returned exactly as it’s stored in the file, so it can contain text such as 2024.3 (build 17).

$cs.File_GetProductVersion(string filepath)

Full path of the file to retrieve the ProductVersion from.

String containing the ProductVersion.

Terminal window
$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):

Terminal window
$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:

Terminal window
$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")
}

$cs.File_GetFileVersion $cs.File_ExistFile