# $cs.MSI_IsMSIFileInstalled

> Convenience check that extracts the ProductCode from msifile and checks whether a product with that code is currently installed on the machine.

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

### Description

Convenience check that extracts the ProductCode from `msifile` and checks whether a product with that code is currently installed on the machine. Windows-only.

### Syntax

$cs.MSI\_IsMSIFileInstalled(string msifile)

### Parameters

#### msifile (String)

Path to the MSI file to check. Throws a `FileNotFoundException` if this file doesn't exist.

### Return value

Boolean, `$true` if a product with this MSI's ProductCode is installed. Returns `$false` (not an exception) if the installed-check itself fails for any other reason.

### Example

**PowerShell**

```powershell
$msiFile = Join-Path $global:Packageroot "pdfsam.msi"
if ($cs.MSI_IsMSIFileInstalled($msiFile)) {
  $cs.Job_WriteLog("pdfsam is already installed, skipping install")
}
```

Use it as an already-installed guard inside `PreInstall`, exiting early instead of skipping just the install step:

```powershell
function PreInstall {
  $cs.Log_SectionHeader('PreInstall', 'o')
  $msiFile = Join-Path $global:Packageroot "pdfsam.msi"
  if ($cs.MSI_IsMSIFileInstalled($msiFile)) {
    Exit-PSScript -exitcode 3330 -exitmessage "$global:AppName is already installed, nothing to do"
  }
}
```

### Related functions

[$cs.MSI_GetProductCodeFromMSI](/capainstaller/powerpacks/cs-msi-getproductcodefrommsi/) [$cs.MSI_IsMSIGuidInstalled](/capainstaller/powerpacks/cs-msi-ismsiguidinstalled/)
