On the array obtained from get_Properties(), use Length property, which is the real property, instead of Count which is a PowerShell automatic property.
Should use method get_Properties() instead of property Properties, but possibly optimize by capturing the array returned while counting the number of available properties in the previous invocation.
Use of the local: scope syntax for built-in variables that are not present in all versions of PowerShell will prevent inadvertent use of a variable from a parent scope that might be unrelated to the built-in variable's purpose.