Counting the members in an AD group

A question came up on the forum about counting the number of members a group has.  There are a number of ways of doing this but this is one of the easiest

$data = @()            
Get-ADGroup -Filter {Name -like "ADL*"} |            
foreach {            
 $data += New-Object -TypeName PSObject -Property @{            
   Name = $_.Name            
   MemberCount = (Get-ADGroupMember -Identity $($_.DistinguishedName) | Measure-Object ).Count            
 }            
}            
$data

Use the Get-ADGroupMember cmdlet and pipe the output to Measure-Object. Take the Count property.

BTW the forums I refer to are at powershell.org  If you haven’t visited I would strongly recommend you do.

Published Wed, Dec 5 2012 19:32 by RichardSiddaway

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: