I'm trying to download all emails from AD groups using PowerShell. The following recursive command works for most groups except any with more than 5000 members (including sub-groups).
Get-AdGroupMember "groupname" -recursive | Get-AdUser -properties Emailaddress | Select EmailAddress | Export-Csv c:\list.csv
The following error occurs with the recursive command returning more than 5000 members:
Get-ADGroupMember : The size limit for this request was exceeded.
The issue I have is my IT department will not increase the max member allowed to be queried (5000) on the AD web server.
A quick web search will yield the following solution but it is not recursive, and I need it to be recursive to get the emails from the sub groups (as we have many sub-groups).
$grp = get-adgroup "groupname" -properties members
$grp.members | get-aduser | Select Name | Export-csv C:list.csv
Is there any other way to download all emails?