Author Posts

December 7, 2016 at 12:34 am

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

December 7, 2016 at 1:39 am

"Better" is in the eye of the beholder. What's wrong with your way? It works.

December 7, 2016 at 7:42 am

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

December 7, 2016 at 9:05 am

if you doesn't glued to pipeline, you can see some tricks here 😉

# 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

December 8, 2016 at 5:04 am

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