Nice script! Works great, however I've had issues with this on SCOM 2012. If I have a server and all its contained objects in Maintenance Mode the server doesn't show up in "Agents where Health State is not Green" It does show the # of objects in maintenance mode under "ObjectCount" though. If I place a single object into MM like a website, I actually get an error in the Script:
Exception setting "ObjectCount": "Cannot set Column 'ObjectCount' to be null. Please use DBNull instead."
At C:\scripts\SCOMHealthCheck.ps1:210 char:1
+ $NewRow.ObjectCount = $ObjectsFound.Count
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterSetValue