Want output with DistributionGroup Name, EmailAddress along with UserName, EmailAddress for AcceptMessagesOnlyFromDLMembers and/or AcceptMessagesOnlyFromSendersOrMembers

Sushant Sawant 1 Reputation point
2022-05-05T14:22:04.937+00:00

Display Name can be same but email addresses cannot be the same for everyone.

I've got the command to get the list of UserName, EmailAddress of the members/users (Internal,External) those are having the permission to send the email to the group. But I couldn't find how to get the DistributionGroup Name & EmailAddress.

I am getting details of only users/members those are having permission to send the email to the specific group via below command
(Get-DistributionGroup -ResultSize Unlimited).acceptmessagesonlyfrom | Get-User | Select-Object DisplayName,userprincipalname,title, windowsemailaddress

Can anyone help me to get the output for users/members those are having permission to send the emails to DG & Unified Group in below format
DG Name DG Email MemberDisplayName MemberUserPrincipalName MemberWindowsEmailAddress

2 Different commands will be fine at this moment but if anyone has a expertise in PSS then i don't mind trying on my Tenant to see the output

Below command gives me output for the DG's has someone who has a permission to send the email to
Get-DistributionGroup -ResultSize Unlimited -filter {(AcceptMessagesOnlyFrom -ne $null) -or (AcceptMessagesOnlyFromDLMembers -ne $null) } | select-object PrimarySMTPAddress,@{Name="AcceptMessagesOnlyFrom";Expression={[string]::join(";",($.AcceptMessagesOnlyFromSendersOrMembers | foreach {Split-Path $ -Leaf}) )}}

Anyones little help will be appreciated

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,115 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
502 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,322 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Newbie Jones 1,301 Reputation points
    2022-05-06T15:22:22.313+00:00

    Try the following;

    $groups =  (Get-DistributionGroup -ResultSize Unlimited -filter {(AcceptMessagesOnlyFrom -ne $null) -or (AcceptMessagesOnlyFromDLMembers -ne $null)}).displayName
    
    ForEach ($distgroup in $groups) {
        (Get-DistributionGroup -identity $distgroup).acceptmessagesonlyfrom.distinguishedName  |
            Get-ADUser -Properties Title, mail, DisplayName |
                Select-Object DisplayName,userprincipalname,title,mail,@{name="distgroup";expression={$distgroup}} |
                    Export-CSV c:\members.csv -NoTypeInformation
    }
    
    1 person found this answer helpful.