Easier way to show a Property

This works fine (and it helps me follow the pipeline) but is there a better way to show the Property “Count”?

Get-ADGroup MyGroup -Server myCompany.com -Properties * | select members -ExpandProperty members | measure | select count


Count
-----
   15

thank you

“Better” is in the eye of the beholder. What’s wrong with your way? It works.

Well, I’m not going to argue with Don Jones, so I’m good, thanks!

if you doesn’t glued to pipeline, you can see some tricks here :wink:

# original
Get-ADGroup MyGroup -Server myCompany.com -Properties * | select members -ExpandProperty members | measure | select count
# get count as int number, but not object property
Get-ADGroup MyGroup -Server myCompany.com -Properties * | select members -ExpandProperty members | measure | select -ExpandProperty count
# but better is
(Get-ADGroup MyGroup -Server myCompany.com -Properties * | select members -ExpandProperty members | measure).Count
# save ssome cpu cycles because members already array and have count property
(Get-ADGroup MyGroup -Server myCompany.com -Properties * | select members -ExpandProperty members).Count
# save some cpu and network when you don't need all properties but members only and selection redundancy
(Get-ADGroup MyGroup -Server myCompany.com -Properties members | select -ExpandProperty members).Count
# and finally 
(Get-ADGroup MyGroup -Server myCompany.com -Properties members).Members.Count
# but prepare to $null if you use PSv2.0 because $null.Count == 0 only on PSv3+
# this can be solved with
@((Get-ADGroup MyGroup -Server myCompany.com -Properties members).Members).Count
# but this is harder to read

ah I was trying to see how I could leverage count as a method but when I saw it as a Property, didn’t think I could do something like your example thus:

(Get-ADGroup MyGroup -Server myCompany.com -Properties * | select members -ExpandProperty members | measure).Count