$cs.MSI_GetProductCodeFromMSI
Description
Section titled “Description”Extracts and returns the ProductCode GUID embedded in an MSI file’s own metadata, without installing anything. Windows-only.
Syntax
Section titled “Syntax”$cs.MSI_GetProductCodeFromMSI(string msifile)
Parameters
Section titled “Parameters”msifile (String)
Section titled “msifile (String)”Path to the MSI file to retrieve the ProductCode from.
Return value
Section titled “Return value”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.
Example
Section titled “Example”Read the ProductCode from the kit’s MSI simply to log it:
$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:
$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}