# $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.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-file-getfileversion/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### 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.

### Syntax

$cs.File_GetFileVersion(string filepath)

### Parameters

#### filepath (String)

Full path of the file to retrieve the FileVersion from.

### Return value

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

### Example

**PowerShell**

```powershell
$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:

```powershell
$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")
}
```

### Related functions

[$cs.File_GetProductVersion](/capainstaller/powerpacks/cs-file-getproductversion/) [$cs.File_ExistFile](/capainstaller/powerpacks/cs-file-existfile/)
