question

SushantSawant-0774 avatar image
0 Votes"
SushantSawant-0774 asked NewbieJones-6218 commented

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

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

windows-server-powershelloffice-exchange-online-itprooffice-exchange-server-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SushantSawant-0774

Since this question is related to scripting, I have added the tags "office-exchange-server-dev" and "windows-server-powershell" to it.
Thanks for your understanding.

0 Votes 0 ·

1 Answer

NewbieJones-6218 avatar image
0 Votes"
NewbieJones-6218 answered NewbieJones-6218 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I've managed to get access to an Exchange Console, but I'm having some discrepancies from commands run in the console vs the ISE.

If someone who has their consoles\ISE setup correctly, can test the above, it would be appreciated.

For example. From the Exchange Console, if I run the following, I get shown quite a few attributes including distinguishedName.
(Get-DistributionGroup -identity $distgroup).acceptmessagesonlyfromwhich

Which is why the following then works.
(Get-DistributionGroup -identity $distgroup).acceptmessagesonlyfrom.distinguishedName

If I pull out the distinguishedNames, you can normally pass all of these together into Get-ADUser without a for-each loop.

If I try through the ISE using Remoting. I only get a single attribute returned (and its not a distinguishedName, and its not something I can just pipe into Get-ADUser).
Therefore the script above is failing at this point. The command runs without error but doesn't return anything because it can't find the distinguishedName property and then fails with a empty identify on the Get-ADUser.

If I pipe (Get-DistributionGroup -identity $distgroup).acceptmessagesonlyfromwhich | Get-Member to view the properties. I get completely different lists between the two.

So the above may or may not work. Depending on where your running it from.
I probably need to reinstall the Exchange 2013 console correctly so I don't need to use remoting.

0 Votes 0 ·