Asked by:
Errors when getting members of all DLs (including nested)

Question
-
Hello, I am running into a few errors when running this command to
1. Get all distribution groups in AD.
2. Count all distribution groups with 1000 members or less (recursively search for nested members)
Get-ADGroup -Filter 'groupcategory -eq "distribution"' | Where-Object { ([array](Get-ADGroupMember –identity $_.distinguishedname -Recursive)).Count -lt 1000} | Measure-Object
Errors:
Get-ADGroup -Filter 'groupcategory -eq "distribution"' | Where-Object { ([array](Get-ADGroupMember –identity $_.distinguishedname -Recursive)).Count -lt 1000} | Measure-Object Get-ADGroupMember : An unspecified error has occurred At line:1 char:82 + ... ect { ([array](Get-ADGroupMember –identity $_.distinguishedname -Recursive)).Cou ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: [Get-ADGroupMember], ADExce on + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMembe Get-ADGroup : The server has returned the following error: invalid enumeration context. At line:1 char:1 + Get-ADGroup -Filter 'groupcategory -eq "distribution"' | Where-Object { ([array] ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ADGroup], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADGroup
Troubleshooting:
- When I run the following I am able to get a count.
(Get-ADGroup -Filter 'groupcategory -eq "distribution"').count
- When I run a "like" filter the command works as well.
Get-ADGroup -Filter "name -like '*test*'" | Where-Object { ([array](Get-ADGroupMember –identity $_.distinguishedname)).Count -gt 3} | Measure-Object
I am running this on Exchange Server 2016, Windows Server 2012 R2 Standard
PS version 4.
- Edited by riz0x Monday, November 12, 2018 9:37 PM progress
- Moved by Bill_Stewart Monday, January 7, 2019 8:16 PM This is not "train me how to use Exchange remoting cmdlets" forum
Monday, November 12, 2018 6:30 PM
All replies
-
Updated original post.Monday, November 12, 2018 9:39 PM
-
Get-ADGroup -Filter 'groupcategory -eq "distribution"' | ForEach-Object{ $group = Get-ADGroupMember –identity $_.distinguishedname -Recursive if($group.Count -lt 1000){ Write-Host ('{0} = {1}' -f $group.Name,$group.count) } }
\_(ツ)_/
Tuesday, November 13, 2018 12:17 AM -
Thanks! This provides me a count for each DL that is under 1000 members. For this solution, I will need to store the distinguished names of these DLs in a variable. What would be the best way to do that since Get-ADGroupMember only allows to specify a single DL?Tuesday, November 13, 2018 10:03 PM