Skip to content

$cs.MSI_IsMSIFileInstalled

Convenience check that extracts the ProductCode from msifile and checks whether a product with that code is currently installed on the machine. Windows-only.

$cs.MSI_IsMSIFileInstalled(string msifile)

Path to the MSI file to check. Throws a FileNotFoundException if this file doesn’t exist.

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.

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

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

$cs.MSI_GetProductCodeFromMSI $cs.MSI_IsMSIGuidInstalled