Skip to content

$cs.MSI_GetProductCodeFromMSI

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

$cs.MSI_GetProductCodeFromMSI(string msifile)

Path to the MSI file to retrieve the ProductCode from.

String, the ProductCode GUID. Returns $null, without throwing an error, if the MSI file doesn’t exist or the ProductCode can’t be read from it.

The MSI must be available when you call the function. The kit folder is downloaded after PreInstall has run, so call it from Install or later.

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

Terminal window
$msiFile = Join-Path $global:Packageroot "kit\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:

Terminal window
$msiFile = Join-Path $global:Packageroot "kit\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
}

$cs.MSI_IsMSIGuidInstalled $cs.MSI_IsMSIFileInstalled