There have been a lot of discussion how to write a proper PowerShell detection method and how to tell Configuration Manager if the application was detected. This post explains how a PowerShell detection method for sccm works and what it should return if the applications is detected as installed.
Detection Methods
Detection methods are used by Configuration Manager to detect if an application is present on the system after the installer completed successfully. Back in the days, SCCM would install a package and everything was good as far as SCCM was concerned as long as the installer returned a good exit code. We know from experience to not trust that as an installation script could run successfully even if several steps inside the script failed. So Microsoft came up with detection methods.
PowerShell Detection Method For SCCM
The only way Configuration Manager knows if an application was detected or not is if the PowerShell detection method returns “Installed”. If it returns something else, Configuration Manager interprets that as the application is not detected. Returning $true and $false may not work every time and you might experience that your application is not detected even if it is.
Here is a PowerShell detection method for an application called PosPay that stores its version number in a file named “version”. The PowerShell script reads out the content of that file and returns “Installed” if it has the correct version after installation or upgrade. I use this as a template for my PowerShell detection methods that reads version information from a file.
# Version to detect $version = "4.15.4" # Path to file $path = "c:\Program Files\PosPay\version" $appVersion = get-content -Path $path if ($appVersion.contains($version)) { Write-Host "Installed" } else { }
You can use PowerShell in many other ways to detect if your application was properly installed, like checking for specific registry keys or verify license information. Just make sure your script returns “Installed” when the application is detected and installed the way you want it.