I have an issue with detection code and I am leaning towards a bug.

Detection Code Outputs

Here is my script:

exit 0



This gives me an exit code of "0" with an empty stdout and stderr. SCCM should see that application as "Not Installed". It sees it as "Installed" Of course, my real script is longer, but I am using this to test and I am not getting the correct response.

Is my thinking backwards? I have found multiple links, articles, and blogs that talk about using powershell as a detection method, but it isn't working for me.

Any hints or ideas? Thanks,

  • Is this the only line of your script, or is there anything before (maybe something that printed something to STDOUT)? – bjoster Jan 25 '19 at 16:18
  • Yes, just for testing. I have also tried these: $x = 20 if ($x -eq 20) { {0} } else { {1} } $x = 20 if ($x -eq 20) { {1} } else { {0} } $x = 20 if ($x -eq 20) {Write-Host "installed"} else {} $x = 20 if ($x -eq 20) {} else {Write-Host "Not Installed} Using this article and others as well: david-obrien.net/2013/12/… – Cusp Jan 25 '19 at 19:34
  • 1
    Is your execution policy set correctly? – user2407464 Jan 26 '19 at 14:17
  • What version of SCCM are you running? If Current Branch, what build (1802, 1806, 1810... etc). On the machines that are detecting improperly, is there a PowerShell profile that's writing to the host. There is a known behavior with SCCM versions prior to 1810 where detection methods are run without using the -noprofile argument so if the machine (or user) has a powershell profile that writes something to the host its picked up as a detection. If this doesn't fit your scenario, maybe post part of your AppDiscovery.log file which could clue us in to whats going on. – Paul G Jan 28 '19 at 2:22

Script exit codes are not supported by SCCM.

SCCM chart

If you'll notice in the chart, anytime the exit code is a non-zero value, the App detection state is "Unknown".

You need to focus on the two outputs of STDOUT and STDERR. You write to STDOUT anytime you write to the console, so a simple Write-Host "Installed" works. You write to STDERR with either Write-Error "Failed" if you want the script to continue after the error, or if you want it to quite you can use a simple THROW.

Took me forever to find this too. Enjoy!

(Credit to https://david-obrien.net/2013/12/configmgr-powershell-application-detection-methods/ for the info)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.