Display AD Group and Member Count

Welcome Forums General PowerShell Q&A Display AD Group and Member Count

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 months, 1 week ago.

  • Author
    Posts
  • #156710

    Participant
    Topics: 9
    Replies: 14
    Points: 108
    Rank: Participant

    Hello,

    I'm trying to write a script to display the AD group name and the count of members in the group.  I'd like to do this for multiple groups, if possible.

    This code displays the count for 1 AD group.

    $ADGroupCnt = (Get-ADGroupMember -Identity "Group Name").count

    Is there any way the code can be changed to include multiple groups and their member count?

    I.E.)

    AD Group  Count
    
    Group1   300
    
    Group2  400

    Thanks,

    Frank

  • #156717

    Participant
    Topics: 1
    Replies: 1481
    Points: 2,366
    Helping Hand
    Rank: Community Hero
    $ListOfGroups = @(
        'GroupName1',
        'GroupName2',
        'GroupName3'
    )
    
    foreach ($Group in $ListOfGroups) {
        [PSCustomObject]@{
            Name = $Group   
            Count = (Get-ADGroupMember -Identity $Group).count
        }
    }

    You may start to learn the very basics of Powershell first.

The topic ‘Display AD Group and Member Count’ is closed to new replies.