# Distribution Lists

**URL:** <https://forums.powershell.org/t/distribution-lists/15394>\
**Category:** PowerShell Help\
**Created:** [December 15, 2020, 3:06am UTC](https://forums.powershell.org/t/distribution-lists/15394 "2020-12-15T03:06:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nenick](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@nenick](https://forums.powershell.org/u/nenick)\
**Post date:** [December 15, 2020, 3:06am UTC](https://forums.powershell.org/t/distribution-lists/15394/1 "2020-12-15T03:06:53Z")

</div>

Hi,

Problem  
2 companies share 3 domains and should be kept separate most of the time for distribution lists etc.  
It is clear we have users from company a in company b’s lists which is wrong.   
We are talking about 100’s, if not 1000’s of lists here.

I need to be able to search all 3 domains lists (and mail enabled security groups) with @company email address for any @companyb UPN and export the lists with members to review as a few may actually need to be a member.

Once reviewed, then remove the x users.

What’s the best way of doing this?

Cheers  
Nick

---

<div class="post-metadata">

**Author:** ![andysvints](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/andysvints/32/1017_2.png) [@andysvints](https://forums.powershell.org/u/andysvints)\
**Post date:** [December 16, 2020, 12:46pm UTC](https://forums.powershell.org/t/distribution-lists/15394/2 "2020-12-16T12:46:04Z")

</div>

Hello nenick39,

One way would be to get all Distribution Groups and mail enabled security groups using [Get-DistributionGroup](https://docs.microsoft.com/en-us/powershell/module/exchange/get-distributiongroup?view=exchange-ps). Then foreach group get distribution group members using [Get-DistributionGroupMember](https://docs.microsoft.com/en-us/powershell/module/exchange/get-distributiongroupmember?view=exchange-ps) **recursively** ( as member of a group could be another group). Then foreach member get his/her email address and apply your filter based on domain name and create custom PS object which will contain couple of properties: **DLName, DLEmailAddress, ContainsCompanyAMembers, ContainsCompanyBMembers,ContainsCompanyCMember** s.  
Add all objects to List and output to file csv/html.  
This type of report will be a starting point to understand how many Distribution Group you have to fix/adjust.

Hope that helps.

---

<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:28pm UTC](https://forums.powershell.org/t/distribution-lists/15394/3 "2024-05-16T20:28:07Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


