Mike
Mike

Reputation: 67

Get-ADGroup where there are more than 500 members (including nested)

I'm trying to run a PowerShell query to bring back groups with more than 500 members in it.

I've tried to run a measure statement & count -gt 500

Get-ADGroup  -Filter {name -like "Distribution*"} -Properties * |
    measure |
    where count -gt 100 |
    select name 

I'd like this to bring back just group names that have > 500 members in it.

Upvotes: 0

Views: 1914

Answers (2)

Jeepm
Jeepm

Reputation: 314

Try this way:

Get-ADGroup  -Filter {name -like "Distribution*"} -Properties * | where {$($_.members.count) -GE 500} | select Name

Upvotes: 2

sysg0blin
sysg0blin

Reputation: 416

This won't be especially quick but you can run this to get an output of each group and a count of how many members there are. The where statement at the end will only output those with more than or equal to 500 members.

Get-ADGroup -Filter * | select Name, @{n="Count";e={(Get-ADGroupMember $_.samaccountname -Recursive).count}} | ? Count -ge 500

Upvotes: 3

Related Questions