Get-ADGroup : The Server Has Returned The Following Error: Invalid Enumerat
Query King | Thu, 14 Oct 2021 at 09:24 hours | Replies : 1 | Points : 100
Category : Automation\Scripts
Hi Team,
I am getting below error while running command Get-ADGroup PowerShell command to get AD group membership. Please help.
Command:
Get-ADGroup -filter * -ResultSetSize 40000 | Select-Object Name, @{n='Members';e={ $_ | Get-ADGroupMember -Recursive | Select-Object -ExpandProperty SamAccountName}} | Export-Csv AllGroupMembers.csv
Error:
Get-ADGroup : The server has returned the following error: invalid enumeration context.
Hi,
I did tried to run the given PowerShell command and i was also getting same error. I did modification to the script and able to get group name those are generating errors.
$AllGroups = Get-ADGroup -filter * -Properties * -ResultSetSize 400000
foreach($Group in $AllGroups)
{
Try { Get-ADGroupMember -Identity $Group -Recursive -ErrorAction Stop | Select-Object @{n='GroupName';e={$Group.name}}, Name | Export-Csv -Append GroupMembers.csv -NoTypeInformation }
catch {Write-Host "Issue in $Group" -BackgroundColor Red}
}
Hope it will help you.