Because the .Count property only exists on an ARRAY and the result of $Comps | Where-Object
can sometimes be an array (when 2 or more objects), $null (empty collection), or the computer object itself (which fortunately has not a .Count property).
Suggestion : Use ALWAYS Set-StrictMode -version Latest at the beginning of all your scripts, you’ll see the error.
One Possible Solution : Use a CAST to an array (the @ operator) as in
Others : Use Measure-Object instead of .Count, or predefine the type of the variable as a System.Object.
Note : PS3 does this cast automatically, but only for some object types, and only for the .Count property.
Risky… and showing you don’t really understand PowerShell pipeline model.