Public/Templates/_shared/Detection-Version.ps1

# Intune detection script to check if the application is installed using the version info in the config.installer.json file

# App name and version as per config.installer.json
$AppName = '##NAME_TEMPLATE'
$Version = '##VERSION_TEMPLATE'
$APFBase = "APF"

# Paths to check for the version info file
$PathsToCheck = @("${env:ProgramFiles(x86)}\$APFBase\AppConfigs\$($AppName)_config.installer.json")
$PathsToCheck += Get-ChildItem -Path "c:\Users\*\AppData\Roaming\$APFBase\AppConfigs\$($AppName)_config.installer.json" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName

foreach ($Path in $PathsToCheck) {
    if (Test-Path -Path $Path) {
        $VersionInfo = Get-Content -Path $Path | ConvertFrom-Json
        if ($VersionInfo.version -eq $Version) {
            Write-Output "The application is installed for all users and matches the required version on file $Path"
            exit 0
        } else {
            # Test if installed version is greater than required version
            $InstalledVersion = $VersionInfo.version
            $RequiredVersion = $Version
            if ([version]$InstalledVersion -gt [version]$RequiredVersion) {
                Write-Output "The application is installed and the installed version is greater than the required version on file $Path"
                exit 0
            } else {
                Write-Output "The version info does not match the required version on file $Path"
                exit 1
            }
        }
    }
}

# If the script hasn't exited by this point, the version file does not exist
Write-Output "The version file does not exist"
exit 1