How to use it
- Pick a check type and fill in its boxes.
- Press Add a check for each extra check.
- Choose if all checks must pass or if any one check may pass.
- Press Copy script.
- In the console, open the deployment type and select the Detection Method tab.
- Select Use a custom script to detect the presence of this deployment type and press Edit.
- Set the script type to PowerShell, paste the script and press OK.
The rule that SCCM uses
The client runs your script and looks at two things: the exit code and the text on STDOUT.
- Exit code 0 and any output on STDOUT: the application is detected.
- Exit code 0 and no output: the application is not detected.
- A non-zero exit code: the script failed. The client reports an error, not a detection result.
The text itself does not matter. One word is enough. This is why a detection script must never write "Not installed". Any text counts as detected.
The script from this tool writes Installed when the checks pass. It writes nothing when they do not pass. Both paths end with exit code 0. An error that the script did not expect ends with exit code 1.
32-bit and 64-bit registry views
A 64-bit Windows keeps two views of the registry. A 32-bit program that writes to HKLM\SOFTWARE lands in HKLM\SOFTWARE\WOW6432Node. A script that reads the wrong view finds nothing.
The script opens the view by name, so the bitness of the PowerShell process does not change the result. Pick the 64-bit view for 64-bit software. Pick the 32-bit view for 32-bit software, and type the key without WOW6432Node. The MSI product code check reads both views.
File checks
You can use variables such as %ProgramFiles% in a path. The file version check compares four-part versions, so 2.5 means 2.5.0.0. It reads the file version numbers, not the product version text.
Leave Run script as 32-bit process on 64-bit clients clear for file checks. A 32-bit process is sent to the 32-bit Program Files and System32 folders.
Test before you deploy
Save the script as a .ps1 file and run it on a PC with the application. You must see Installed. Run it on a PC without the application. You must see nothing.
Questions
Why does my application show as installed when it is not?
The script wrote something to STDOUT. Any output with exit code 0 means detected. Look for a stray value on a line by itself, a Write-Host or Write-Output line, or a command that returns an object.
Where do I find the MSI product code?
Look in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall and in the same key under WOW6432Node. An MSI install has a key named with its product code in braces. The product code often changes with each new version of the product.
Does the script need to be signed?
That depends on the client setting "PowerShell execution policy" under Computer Agent. With Bypass, the client runs unsigned scripts. With All Signed, you must sign the script.
Which user runs the detection script?
For a deployment type that installs for the system, the script runs as the local SYSTEM account. An HKCU check then reads the registry of SYSTEM, not of the signed-in user. Use HKLM checks for system installs.