Get-DistributionGroup

Glenn Maxwell 11,136 Reputation points
2024-08-11T14:30:32.8866667+00:00

I have dynamic distribution lists in Exchange Online. I have a user and want to find out which dynamic distribution lists this user is a member of. I want to try something like the following, but I’m not sure if it's correct

Get-DynamicDistributionGroup -ResultSize Unlimited | Where-Object { (Get-DistributionGroupMember $_.Identity).PrimarySmtpAddress -eq 'user1@contoso.com' }

Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,494 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,608 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
2,076 questions
0 comments No comments
{count} votes

Accepted answer
  1. Noah Ma-MSFT 2,725 Reputation points Microsoft Vendor
    2024-08-12T05:28:33.7833333+00:00

    Hi @Glenn Maxwell ,

    Welcome to the Microsoft Q&A platform!

    Based on your description, I understand you want to find out which dynamic distribution lists the user is a member of via PowerShell.

    After my test, you could do this with the following script as the screenshot shows.

    $userEmail = "user@example.com"
    $dynamicDLs = Get-DynamicDistributionGroup
    
    foreach ($dl in $dynamicDLs) {
    $filter = $dl.RecipientFilter
    $members = Get-Recipient -RecipientPreviewFilter $filter
    if ($members.PrimarySmtpAddress -contains $userEmail) {
    Write-Output "$($userEmail) is a member of $($dl.Name)" 
    } 
       }
    

    User's image

    If the answer is helpful, please click "Accept Answer" and kindly upvote it.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.