Question

As far as I know Get-Member can display all the members of an object, but I'm seeing a Count member that I can't explain:

PS> $job = start-job {dir c:\ }
PS> $job | get-member -Force -View All -MemberType All | select-string Count
# outputs nothing
PS> $job.Count
1

Where is the Count member coming from?

Was it helpful?

Solution

This is a synthetic property that was added in V3: http://blogs.msdn.com/b/powershell/archive/2012/06/14/new-v3-language-features.aspx

You can now use Count or Length on any object, even if it didn’t have the property. If the object didn’t have a Count or Length property, it will will return 1 (or 0 for $null). Objects that have Count or Length properties will continue to work as they always have.

PS> $a = 42 
PS> $a.Count 
1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top