# Identifying users who exist in 2 groups

**URL:** https://forums.powershell.org/t/identifying-users-who-exist-in-2-groups/1264
**Category:** PowerShell Help
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/identifying-users-who-exist-in-2-groups/1264 "2011-12-31T18:30:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)
#### Post date: [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/identifying-users-who-exist-in-2-groups/1264/1 "2011-12-31T18:30:00Z")

</div>

by blamb at 2012-11-05 14:11:24

> Greetings,  
>   
> I have need to produce a list of users from one list that exist in a second list (or more accurately, those who exist in both lists). Here is a bit of code that I came up with (which works):  
>   
> `# Large group that contains many users from many OUs$grp1 = "Big_User_Group"# Smaller group containing users from only a few OUs - it is a group of groups$grp2 = "Focused_User_Group"$a = Get-QADGroupMember $grp2 -SizeLimit 0 -Indirect foreach($User in $a) {	if (Get-QADMemberOf $User -Name $grp1) { "{0,-30}{1}" -f $User.Name,$User.ParentContainerDN	}}`  
>   
> It is pretty basic in approach, fairly non-elegant and quite slow (or should I say ponderous). Additionally, if I wanted to expand this to include additional groups (say I wanted to locate someone in 4 groups), I think it would get even slower.  
>   
> Did I miss the boat on this. I tried looking through the forum, but wasn’t sure exactly what to look under. Any input would be appreciated.  
>   
> Thanks.

by Klaas at 2012-11-06 01:15:04

> `Get-QADUser -MemberOf ‘Big_User_Group’,‘Focused_User_Group’`  
>   
> It seems too easy to be true, but it works for me.

by blamb at 2012-11-06 10:22:04

> Face::Palm  
>   
> Very nice and oh so elegant. Here is a slight mod I had to do due to one group being a collection of groups:  
>   
> `Get-QADUser -IndirectMemberOf $grp1, $grp2`  
> but it work well - still a bit ponderous, but not as much as the original code.  
>   
> Thanks.

---

<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, 9:02pm UTC](https://forums.powershell.org/t/identifying-users-who-exist-in-2-groups/1264/2 "2024-05-16T21:02:34Z")

</div>


