Tabulate property values?

Welcome Forums General PowerShell Q&A Tabulate property values?

This topic contains 4 replies, has 4 voices, and was last updated by

3 years, 8 months ago.

  • Author
  • #25544

    Points: 0
    Rank: 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:

    Name Title
    _____ _____
    Bob Manager
    Alice Executive
    Charlie Manager

    I want to say something like Get-ADUser -filter * -property title | select-object title -unique | "magic happens here"

    And get a result like:

    Title Count
    —— ——–
    Manager 2
    Executive 1

    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.

  • #25545

    Points: 0
    Rank: 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.

  • #25546

    Points: 438
    Helping Hand
    Rank: Contributor

    Should be this easy:

    Get-ADUser -filter * -property title | Group-Object -Property Title -NoElement | Sort-Object -Property Count
  • #25550

    Points: 0
    Rank: 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!

  • #25616

    Points: 57
    Rank: 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.