$cs.MSI_IsMSIFileInstalled
Description
Section titled “Description”Convenience check that extracts the ProductCode from msifile and checks whether a product with that code is currently installed on the machine. Windows-only.
Syntax
Section titled “Syntax”$cs.MSI_IsMSIFileInstalled(string msifile)
Parameters
Section titled “Parameters”msifile (String)
Section titled “msifile (String)”Path to the MSI file to check. Throws a FileNotFoundException if this file doesn’t exist.
Return value
Section titled “Return value”Boolean, $true if a product with this MSI’s ProductCode is installed. Returns $false (not an exception) if the installed-check itself fails for any other reason.
Example
Section titled “Example”$msiFile = Join-Path $global:Packageroot "pdfsam.msi"if ($cs.MSI_IsMSIFileInstalled($msiFile)) { $cs.Job_WriteLog("pdfsam is already installed, skipping install")}Use it as an already-installed guard inside PreInstall, exiting early instead of skipping just the install step:
function PreInstall { $cs.Log_SectionHeader('PreInstall', 'o') $msiFile = Join-Path $global:Packageroot "pdfsam.msi" if ($cs.MSI_IsMSIFileInstalled($msiFile)) { Exit-PSScript -exitcode 3330 -exitmessage "$global:AppName is already installed, nothing to do" }}