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.