Skip to content

$cs.File_GetFileVersion

Reads the FileVersion from a file’s version resource. This is distinct from ProductVersion (see $cs.File_GetProductVersion) — the two can differ for the same binary. Throws FileNotFoundException if filepath doesn’t exist.

$cs.File_GetFileVersion(string filepath)

Full path of the file to retrieve the FileVersion from.

String containing the FileVersion, e.g. "10.3.3.99".

Terminal window
$filepath = Join-Path ${env:ProgramFiles} "Mozilla Firefox\firefox.exe"
if ($cs.File_ExistFile($filepath))
{
$installedVersion = $cs.File_GetFileVersion($filepath)
if ([version]$installedVersion -ge [version]"10.3.3.99")
{
Exit-PSScript -exitcode 3330 -exitmessage "Firefox is already up to date"
}
}

Compare an installed binary’s version against the version being deployed by this PowerPack, skipping install if it’s not newer:

Terminal window
$targetVersion = "4.2.1.0"
$installedExe = Join-Path ${env:ProgramFiles(x86)} "Contoso\Agent\agent.exe"
if ($cs.File_ExistFile($installedExe))
{
$currentVersion = $cs.File_GetFileVersion($installedExe)
if ([version]$currentVersion -ge [version]$targetVersion)
{
Exit-PSScript -exitcode 3330 -exitmessage "Installed version $currentVersion is already up to date, skipping install"
}
$cs.Job_WriteLog("Upgrading from $currentVersion to $targetVersion")
}

$cs.File_GetProductVersion $cs.File_ExistFile