query on mail contacts/mail users

Rising Flight 4,596 Reputation points
2024-11-06T22:30:59.5466667+00:00

Hi All,

I am working in an Exchange 2016 hybrid environment. I have mail contacts and mail users in Exchange 2016, as well as mail contacts, mail users, and external users in Exchange Online. I also have distribution lists (DLs) in both Exchange On-Premises and Exchange Online.

Is it possible to identify the distribution lists, both on-premises and online, in which these mail contacts, mail users, and external users are members?

Please guide me.

Microsoft Exchange Online
Exchange Server
Exchange Server
A family of Microsoft client/server messaging and collaboration software.
1,355 questions
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,608 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,690 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,145 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Alex Zhang-MSFT 1,990 Reputation points Microsoft Vendor
    2024-11-07T02:36:34.3133333+00:00

    Hello, @Rising Flight,

    Welcome to the Microsoft Q&A platform!

    Based on your requirements, I can help guide you through identifying the distribution lists (DLs) in which your mail contacts, mail users, and external users are members in both Exchange On-Premises and Exchange Online environments.

    1. Connect to Exchange On-Premises: Open the Exchange Management Shell on your Exchange 2016 server and run the following command to get the distribution groups and their members.
    Get-DistributionGroup | ForEach-Object { Get-DistributionGroupMember $_.Identity | Select-Object @{Name="GroupName";Expression={$_.Identity}}, Name, RecipientType }
    
    1. Connect to Exchange Online: Open the Windows PowerShell and connect to Exchange Online using the following commands.
    $UserCredential = Get-Credential
    Connect-ExchangeOnline -UserPrincipalName $UserCredential.UserName -ShowProgress $true
    

    Once connected, run the following command to get the distribution groups and their members.

    Get-DistributionGroup | ForEach-Object { Get-DistributionGroupMember $_.Identity | Select-Object @{Name="GroupName";Expression={$_.Identity}}, Name, RecipientType }
    
    1. Identify Members: The output of these commands will list all distribution groups along with their members, including mail contacts, mail users, and external users. You can export this information to a CSV file for easier analysis.
    Get-DistributionGroup | ForEach-Object { Get-DistributionGroupMember $_.Identity | Select-Object @{Name="GroupName";Expression={$_.Identity}}, Name, RecipientType } | Export-Csv -Path "DistributionGroupMembers.csv" -NoTypeInformation
    

    By running these commands, you will be able to identify the distribution lists in both your on-premises and online environments and see which mail contacts, mail users, and external users are members of each list.


    If the answer is helpful please click on ACCEPT ANSWER as it could help other members of the Microsoft Q&A community who have similar questions and are looking for solutions.

    Thank you for your support and understanding.

    Best Wishes,

    Alex Zhang


  2. Amit Singh 4,986 Reputation points
    2024-11-07T06:09:05.6166667+00:00

    Yes, you can identify which distribution lists both on-premises and in Exchange Online contain your mail contacts, mail users, and external users as members. Since you have a hybrid setup, you need to check both environments separately.

    1.       For On-Premises Exchange 2016:- Run the following command using PowerShell -

    Get-DistributionGroup | ForEach-Object {Get-DistributionGroupMember $_ | Where-Object {$_.PrimarySMTPAddress -eq "[email protected]"}}
    

    2.       For Exchange Online:- First, connect to Exchange Online PowerShell by running-

    Connect-ExchangeOnline -UserPrincipalName [[email protected]]   
    

    Run the command to see all distribution lists -

    Get-DistributionGroup | ForEach-Object {Get-DistributionGroupMember $_ | Where-Object {$_.PrimarySMTPAddress -eq "[email protected]"}}
    

    Replace email address with your emails. Let me know if you have any query in above steps.

    0 comments No comments

  3. Rising Flight 4,596 Reputation points
    2024-11-09T22:31:35.7+00:00

    Lets say i have a csv file in the below format. will the below syntax fetch me mailuser/mailcontact/externaluser that are members of the DL.

    DLAlias
    [email protected]
    [email protected]
    
    Import-Csv c:\windows\temp\list.csv | ForEach-Object {
        Get-DistributionGroup -Identity $_.DLAlias | ForEach-Object {
            Get-DistributionGroupMember -Identity $_.DLAlias | Where-Object {
                ($_.RecipientType -eq "MailUser") -or 
                ($_.RecipientType -eq "MailContact") -or 
                ($_.RecipientTypeDetails -eq "GuestMailUser") -or 
                ($_.RecipientTypeDetails -eq "ExternalUser")
            }
        }
    }
    

    will the above syntax fetch me external users created from Azure AD. how do i export the output to csv file. please guide me. will the above syntax work for unified groups if i change it from get-distributiongroup to get-unifiedgroup.

    guest


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.