Score:0

Powershell - get name and mobile from group with more than 5000 members

td flag

I need to extract the name and mobile of all users in an AD group that consists of more than 5000 members.

When I previously did this I only had to extract the name, and this code solved my problem

Get-ADGroup 'xxx' -Properties Member | Select-Object -ExpandProperty Member | Sort
Get-ADGroup "xxx" -Properties Member | Select-Object -ExpandProperty Member | Get-ADObject | Select Name | Sort Name
((Get-ADGroup "xxx" -Properties member).member).count
Get-ADGroup "xxx" -Properties Member | Select-Object -ExpandProperty Member | Get-ADObject | Select Name | Sort Name  | Export-Csv C:\temp\exportmembers.csv -Encoding UTF8 -NoTypeInformation

Since groups don't contain the property "mobile" I'm unsure how to go about this.

Any help is appreciated.

Score:1
in flag

You can get all group members directly using Get-ADGroupMember, even with subgroups

get-adgroup 'xxxx' |Get-ADGroupMember -Recursive |
  get-aduser -Properties name,mobile |sort name |select name,mobile |
  Export-Csv C:\temp\exportmembers.csv -Encoding UTF8 -NoTypeInformation

For the +5000 member issue, just add the property to Get-AdObject and Select-Object

Get-ADGroup "xxx" -Properties Member | Select-Object -ExpandProperty Member | 
  Get-ADObject -Properties mobile | Select Name,mobile | Sort Name  | 
  Export-Csv C:\temp\exportmembers.csv -Encoding UTF8 -NoTypeInformation
Lars avatar
td flag
Thanks for the reply, but because there's more than 5000 members in the group I get an error saying "Get-ADGroupMember : The size limit for this request was exceeded". When I googled I found that the cap is 5000 members for ADGroupMember, which is why I included that in the OP. Any chance you know how to get around this?
in flag
@Lars see my edit
Lars avatar
td flag
Thank you so much!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.