# Get members list from multiple AD groups

**URL:** <https://forums.powershell.org/t/get-members-list-from-multiple-ad-groups/20344>\
**Category:** PowerShell Help\
**Created:** [September 5, 2022, 1:43pm UTC](https://forums.powershell.org/t/get-members-list-from-multiple-ad-groups/20344 "2022-09-05T13:43:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikola\_Lubomirov](https://avatars.discourse-cdn.com/v4/letter/n/fbc32d/32.png) [@Nikola\_Lubomirov](https://forums.powershell.org/u/Nikola_Lubomirov)\
**Post date:** [September 5, 2022, 1:43pm UTC](https://forums.powershell.org/t/get-members-list-from-multiple-ad-groups/20344/1 "2022-09-05T13:43:00Z")

</div>

Hello I have this code:

```auto
$groups = "Group1", "Group2", "Group3","Group4"
$results = foreach ($group in $groups) {
    Get-ADGroupMember $group | select samaccountname, name, mail, @{n='GroupName';e={$group}}, @{n='Description';e={(Get-ADGroup $group -Properties description).description}}
}
$results
$results | Export-csv C:\GroupMemberShip.csv -NoTypeInformation

```

and I wanted to get also email address, but the above code doesn’t return this value. Any ideas what to change in case to get also email address?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 5, 2022, 3:03pm UTC](https://forums.powershell.org/t/get-members-list-from-multiple-ad-groups/20344/2 "2022-09-05T15:03:53Z")

</div>

Nikola,  
Welcome to the forum. 👋🏽

When you post code, sample data, console output or error messages please format it as code using the _preformatted text_ button ( **\</\>** ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

[How to format code in PowerShell.org](https://aws1.discourse-cdn.com/business5/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) \<---- Click 👆🏽 😉

> [@Nikola\_Lubomirov](#):
>
> I wanted to get also email address

You need to query each individual user account the same way you determine the group description with a calculated property.

BUT: Depending on the groups you’re processing there could be a lot of redundancy when you query a lot users who are members of multiple groups at the same time.

---

<div class="post-metadata">

**Author:** ![Nikola\_Lubomirov](https://avatars.discourse-cdn.com/v4/letter/n/fbc32d/32.png) [@Nikola\_Lubomirov](https://forums.powershell.org/u/Nikola_Lubomirov)\
**Post date:** [September 5, 2022, 4:15pm UTC](https://forums.powershell.org/t/get-members-list-from-multiple-ad-groups/20344/3 "2022-09-05T16:15:55Z")

</div>

Hello Olaf,  
Thank you for that, I’ve edited the post to have the correct format (sorry for that).  
So you think I should do it same way as for the group description something like that:  
`Get-ADGroupMember $group | for each {$user = get-aduser $_ -properties mail` etc

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 5, 2022, 4:18pm UTC](https://forums.powershell.org/t/get-members-list-from-multiple-ad-groups/20344/4 "2022-09-05T16:18:56Z")

</div>

It depends on the AD structure and on the amount of users and groups you have but - **yes** - that’s what I meant. 😉

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/get-members-list-from-multiple-ad-groups/20344/5 "2024-05-16T20:16:39Z")

</div>


