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, or $null if it can’t be read from the MSI.

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

Terminal window
$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:

Terminal window
$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
}

$cs.MSI_IsMSIGuidInstalled $cs.MSI_IsMSIFileInstalled