extract Acceptmessagesfrom members list of a DL

hi expert,

i want to know how to extract the acceptmessagefrom members list of a DL , i am able to do it but the the problem is the output, it shows DN name , and some of the user DN is too large and it is not come in CSV


can i do anything in cmdlet that i can extract the user email id instead or DN






No Data
  • It is important to note that there are two fields that contain 'accept from' information for a Distribution Group.

    • "AcceptMessagesOnlyFrom"
    • "AcceptMessagesOnlyFromDLMembers"


    "AcceptMessagesOnlyFrom" contains mailboxes only

    "AcceptMessagesOnlyFromDLMembers" may contain mailboxes as well as Distribution Groups


    You can start with the code below which will simply display results and work from there to customize to your needs.


    $Dl = get-distributiongroup "some DL you know contains restrictions"

    $OnlyFrom = $Dl.AcceptMessagesOnlyFrom

    $OnlyMembers = $Dl.AcceptMessagesOnlyFromDLMembers

    Write-host "AcceptMessagesOnlyFrom:" -foregroundcolor Red

    foreach ($User in $onlyFrom) {

       $mbx = Get-mailbox $User

       write-host $mbx.primarysmtpaddress -foregroundcolor green


    Write-host "AcceptMessagesOnlyFromDLMembers:" -foregroundcolor Red

    ForEach ($Obj in $OnlyMembers) {

       $MB = get-mailbox $Obj -erroraction silentlycontinue

       $NewDL = get-distributiongroup $Obj -erroraction silentlycontinue

       if ($NewDL -NotLike $null) {

          write-host $NewDL.primarysmtpaddress -foregroundcolor green

       } Else {

          write-host $MB.primarysmtpaddress -foregroundcolor Yellow