Other Configuration Manager-related features and issues
<fyi, I do not work for Microsoft, I'm just another admin like you>
Years and years ago, I defaulted to having my powershell scripts within CIs to evaluate for compliant or non-compliant based on a string. like...
Write-host "Complaint"
and the string 'Compliant' means it is compliant, vs. $true or $false.
This is because although I personally never experienced it, on a different team, they found that based on some weird combination of Operations System and possibly what Powershell was installed, what they found was that SOMETIMES (not always, but sometimes), if they asked for a $true $false, what was actually submitted was a 1 or 0 (as a string, not boolean); so of course it was "non-compliant' and would trigger the remediation script.
That was YEARS ago, but since that knowledge, I've always used a string in a CI for compliant/non-compliant, not $true/$false.
For fun, recreate your CI using string, and have it spit out a write-host "whatever means compliant", and test for that.
Bonus: with some 'complicated SQL", I also love doing strings...because of the box spits out anything other than 'Compliant', I can (with complicated sql) see what that non-compliant reason was. In your case, you could spit out...
# More than 5 profiles → non-compliant
write-host [string]$profiles.Count
}
=================
OPTIONALLY
Based on that specific script you have, instead of Boolean, make it be Integer, and the "what means compliant" is Less than 5