PowerShell for Windows Admins

Dec 5 2012   1:31PM GMT

Counting the members in an AD group

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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            

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.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: