This topic contains 4 replies, has 4 voices, and was last updated by
May 21, 2015 at 11:24 am #25544ParticipantPoints: 0Rank: Member
I'm looking to be able to query a data source (Active Directory though any other should suffice), where I pull in the values in a property, and also calculate how many occurrences of each value are present in that list.
So assuming AD Users:
I want to say something like Get-ADUser -filter * -property title | select-object title -unique | "magic happens here"
And get a result like:
Any ideas? I tried "for-each"ing the unique list back into a retrieval from AD in a subexpression and then pulling out a count, but PowerShell just kept laughing and laughing at me.
May 21, 2015 at 11:44 am #25545MemberPoints: 0Rank: Member
That's more or less what Group-Object does:
Get-ADUser -Filter * -Property Title | Select-Object * | Group-Object -Property Title
I'm not sure if the "Select-Object *" part is necessary or not, but the AD cmdlets sometimes misbehave in a pipeline, so I put it there out of habit and caution.
May 21, 2015 at 11:48 am #25546ParticipantPoints: 438Rank: Contributor
Should be this easy:
Get-ADUser -filter * -property title | Group-Object -Property Title -NoElement | Sort-Object -Property Count
May 21, 2015 at 12:45 pm #25550ParticipantPoints: 0Rank: Member
Outstanding. I'm a little embarrassed to realize that Group-Object has been in PowerShell since version 3.0 and I didn't know...
Thanks all for your help!
May 25, 2015 at 4:14 am #25616ParticipantPoints: 57Rank: Member
Not to rub salt in the wound, but if I recall correctly group-object has been around since PS1.0... Don't be embarrassed, I'm continuously finding out new things with/about PowerShell. IT is a continuous learning experience. Once you consider yourself an expert, you've already fallen behind.
The topic ‘Tabulate property values?’ is closed to new replies.