In old environments we can meet a lot of old groups in Ad which was created, but often are not used or even without any member. I will show you short script which will find all AD groups and give us count of members in every of them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$groups = Get-ADGroup -Filter * $results = @() foreach ($group in $groups) { $members = Get-ADGroupMember -Identity $group.DistinguishedName -Recursive | Measure-Object | Select-Object -ExpandProperty Count $result = [PSCustomObject]@{ GroupName = $group.Name MemberCount = $members } $results += $result } $results = $results | Sort-Object -Property MemberCount $results | Format-Table -AutoSize |
As a result we will have list of all groups with member count sorted from 0 to up. Below show you fragment of that.