There are different methods to get this information when the group is small, but the problem shows up when a group contains thousands of members.
The first cmdlet that I tried was:
$members = Get-ADGroupMember -Identity “Group Name”
The idea is execute the follow line:
$members.count
But I got this error: “The size limit for this request was exceeded”
And the same with the follow cmd lets:
- Get-ADGroupMember -Identity “Group Name” > C:\Temp\members.txt (even exporting the result to a csv file).
- Get-ADGroupMember -Identity “Group Name” | Measure-Object
- Get-ADGroupMember -Identity “Group Name” | Measure-Object | select count
The command that worked properly for me was:
$members = Get-ADGroup -Identity “Group Name” -Properties Members
$members.count
I my case, I ran this command for a group that contains more than 7k members.