$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.
A product counts as installed when Windows Installer reports it as fully installed for the machine, or for the account that runs the PowerPack. Products that are only advertised, or installed per-user for another user, return $false. To check without the MSI file, for example in PreInstall before the kit is downloaded, use $cs.MSI_IsMSIGuidInstalled.
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 "kit\pdfsam.msi"if ($cs.MSI_IsMSIFileInstalled($msiFile)) { $cs.Job_WriteLog("pdfsam is already installed, skipping install")}Use it as an already-installed guard at the start of Install, exiting early instead of skipping just the install step. The check can’t go in PreInstall, because the kit folder is downloaded after PreInstall has run:
function Install { $cs.Log_SectionHeader('Install', 'o') $msiFile = Join-Path $global:Packageroot "kit\pdfsam.msi" if ($cs.MSI_IsMSIFileInstalled($msiFile)) { Exit-PSScript -exitcode 3330 -exitmessage "$global:AppName is already installed, nothing to do" }}