# $cs.MSI_GetProductCodeFromMSI

> Extracts and returns the ProductCode GUID embedded in an MSI file's own metadata, without installing anything.

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

### Description

Extracts and returns the ProductCode GUID embedded in an MSI file's own metadata, without installing anything. Windows-only.

### Syntax

$cs.MSI\_GetProductCodeFromMSI(string msifile)

### Parameters

#### msifile (String)

Path to the MSI file to retrieve the ProductCode from.

### Return value

String, the ProductCode GUID, or `$null` if it can't be read from the MSI.

### Example

**PowerShell**

Read the ProductCode from the kit's MSI simply to log it:

```powershell
$msiFile = Join-Path $global:Packageroot "pdfsam.msi"
$msiGuid = $cs.MSI_GetProductCodeFromMSI($msiFile)
$cs.Job_WriteLog("ProductCode from MSI: $msiGuid")
```

Extract the ProductCode from a newer kit MSI in order to uninstall a previous version by GUID before installing the new one:

```powershell
$msiFile = Join-Path $global:Packageroot "pdfsam.msi"
$newProductCode = $cs.MSI_GetProductCodeFromMSI($msiFile)
$oldProductCode = '{AC76BA86-1033-FF00-7760-BC15014EA700}'
if (($oldProductCode -ne $newProductCode) -and $cs.MSI_IsMSIGuidInstalled($oldProductCode)) {
  $cs.Job_WriteLog("Removing previous version ($oldProductCode) before installing $newProductCode")
  Start-Process "msiexec.exe" -ArgumentList "/x $oldProductCode /qn /norestart" -Wait
}
```

### Related functions

[$cs.MSI_IsMSIGuidInstalled](/capainstaller/powerpacks/cs-msi-ismsiguidinstalled/) [$cs.MSI_IsMSIFileInstalled](/capainstaller/powerpacks/cs-msi-ismsifileinstalled/)
