$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, or $null if it can’t be read from the MSI.
Example
Section titled “Example”Read the ProductCode from the kit’s MSI simply to log it:
$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:
$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}