$cs.File_GetFileVersion
Description
Section titled “Description”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, and throws an error if the file has no version information.
The value is returned exactly as it’s stored in the file. Some vendors add text to it, for example 10.0.19041.1 (WinBuild.160101.0800). Casting such a value to [version] fails, so strip the extra text before you compare versions.
Syntax
Section titled “Syntax”$cs.File_GetFileVersion(string filepath)
Parameters
Section titled “Parameters”filepath (String)
Section titled “filepath (String)”Full path of the file to retrieve the FileVersion from.
Return value
Section titled “Return value”String containing the FileVersion, e.g. "10.3.3.99".
Example
Section titled “Example”$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:
$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")}