# $cs.File_GetProductVersion

> Reads the ProductVersion from a file's version resource.

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

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

$cs.File_GetProductVersion(string filepath)

### Parameters

#### filepath (String)

Full path of the file to retrieve the ProductVersion from.

### Return value

String containing the ProductVersion.

### Example

**PowerShell**

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

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

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

### Related functions

[$cs.File_GetFileVersion](/capainstaller/powerpacks/cs-file-getfileversion/) [$cs.File_ExistFile](/capainstaller/powerpacks/cs-file-existfile/)
