Share via

error exporting AD-users

Glenn Maxwell 13,761 Reputation points
2021-08-13T02:06:20.34+00:00

Hi All

I am using the below syntax, one of my security group has more than 20000 users, i want to export all these users to csv file. i am getting error with resultsize unlimited parameter. please guide me

Get-ADGroupMember -resultsize unlimited -Identity "MySecurityGroup" -Recursive | Get-ADUser -Properties Title,physicalDeliveryOfficeName,office,Department | Select Name,UserprincipalName,physicalDeliveryOfficeName,Office,Title,Department,SamAccountName,DistinguishedName | Export-CSV -Path C:\temp\output.csv -NoTypeInformation

To add multiple users to a AD group is the below syntax correct?

Import-CSV C:\temp\input.csv | ForEach {Add-ADGroupMember -Identity Group2 -Member $_.users}

Windows for business | Windows Server | User experience | PowerShell

Answer accepted by question author

Siva-kumar-selvaraj 15,741 Reputation points Volunteer Moderator
2021-08-13T17:07:19.023+00:00

Hello @Glenn Maxwell ,

Thanks for reaching out.

The number of objects that Get-ADGroupMember can return is restricted by a limit in the Active Directory Web Services (ADWS) : MaxGroupOrMemberEntries=5000

Specifies the maximum number of group members (recursive or non-recursive), group memberships, and authorization groups that can be retrieved by the Active Directory module Get-ADGroupMember, Get-ADPrincipalGroupMembership, and Get-ADAccountAuthorizationGroup cmdlets. Set this parameter to a higher value if you anticipate these cmdlets to return more than 5000 results in your environment.

Here are some similar threads for your reference : Microsoft technet & stackoverflow .

Coming back to your second question: Yes, following syntax must work Import-CSV C:\temp\input.csv | ForEach {Add-ADGroupMember -Identity Group2 -Member $_.users} as I was able add members successfully with same syntax form my lab. Here are some example based on decision control.

Hope this helps.

------
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.