# Export a list of all groups 2 users are a member of

**URL:** https://forums.powershell.org/t/export-a-list-of-all-groups-2-users-are-a-member-of/17575
**Category:** PowerShell Help
**Created:** [September 20, 2021, 10:33pm UTC](https://forums.powershell.org/t/export-a-list-of-all-groups-2-users-are-a-member-of/17575 "2021-09-20T22:33:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![potterscott](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@potterscott](https://forums.powershell.org/u/potterscott)
#### Post date: [September 20, 2021, 10:33pm UTC](https://forums.powershell.org/t/export-a-list-of-all-groups-2-users-are-a-member-of/17575/1 "2021-09-20T22:33:12Z")

</div>

I am needing to export 2 AD users and groups they are members of. Is there a way of accomplishing this with one export? I would like 2 columns, 1 for each user and the groups.

Get-AdPrincipalGroupMembership e56836 | select name | sort-object -Property name

---

<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 20, 2021, 11:01pm UTC](https://forums.powershell.org/t/export-a-list-of-all-groups-2-users-are-a-member-of/17575/2 "2021-09-20T23:01:25Z")

</div>

> [@potterscott](#):
>
> Is there a way of accomplishing this with one export?

What exactly do you mean with that? `Get-AdPrincipalGroupMembership` does not take arrays for the` -Identity` parameter. So you’d need any kind of loop.

This will work:

```auto
$IdentityList = 'UserOne','UserTwo'
foreach($Identity in $IdentityList){
    [PSCustomObject]@{
        Name = $Identity
        Groups = (Get-ADPrincipalGroupMembership -Identity $Identity).Name -join ', '
    }
}

```

---

<div class="post-metadata">

### Author: ![potterscott](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@potterscott](https://forums.powershell.org/u/potterscott)
#### Post date: [September 21, 2021, 12:42pm UTC](https://forums.powershell.org/t/export-a-list-of-all-groups-2-users-are-a-member-of/17575/3 "2021-09-21T12:42:39Z")

</div>

> [@Olaf](#):
>
> ```auto
> $IdentityList = 'UserOne','UserTwo'
> foreach($Identity in $IdentityList){
> [PSCustomObject]@{
> Name = $Identity
> Groups = (Get-ADPrincipalGroupMembership -Identity $Identity).Name -join ', '
> }
> }
> 
> ```

Thanks that is perfect. Is there a way to export that out to a csv?

---

<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 21, 2021, 3:43pm UTC](https://forums.powershell.org/t/export-a-list-of-all-groups-2-users-are-a-member-of/17575/4 "2021-09-21T15:43:04Z")

</div>

> [@potterscott](#):
>
> Is there a way to export that out to a csv?

That’s a joke, isn’t it? 🤔

How long would it have taken you to try it?

---

<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:21pm UTC](https://forums.powershell.org/t/export-a-list-of-all-groups-2-users-are-a-member-of/17575/5 "2024-05-16T20:21:22Z")

</div>


