Export DL owners in smtp formt

Austin Sundar 436 Reputation points
2021-11-23T07:32:59.773+00:00

i am trying to export DL owners in smtp format. but the formatting seems to incorrect

These are the challenges facing

  • some of the DLs have multiple owners
  • export managed by field in smtp format

the code that i am using is

Get-DistributionGroup -ResultSize unlimited|?{$_.DisplayName -like "*user*"}| Select DisplayName, PrimarySmtpAddress,@{Name='EmailAddresses'; Expression={$_.EmailAddresses -join ","}}, OrganizationalUnit, @{n="ManagedBy";e={(Get-Recipient $($_.ManagedBy)).PrimarySmtpAddress -join ","}}, LegacyExchangeDN, DistinguishedName|Export-Csv "DLs _$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv" -NoTypeInformation
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,360 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 95,671 Reputation points MVP
    2021-11-23T08:07:22.127+00:00

    I'd suggest you use a proper script instead of oneliner, than handle those challenges accordingly. Looping over each owner should give you the possibility to fetch the corresponding SMTP address, which you can then stitch together.

    1 person found this answer helpful.
    0 comments No comments

  2. Kael Yao-MSFT 37,496 Reputation points Microsoft Vendor
    2021-11-24T06:15:15.197+00:00

    Hi @Austin Sundar

    If there are multiple owners, you may modify the @{n="ManagedBy";e={(Get-Recipient $($_.ManagedBy)).PrimarySmtpAddress -join ","}}, part to export all owners.

    Get-DistributionGroup -ResultSize unlimited | ?{$_.DisplayName -like "*user*"} | Select DisplayName, PrimarySmtpAddress,@{Name='EmailAddresses'; Expression={$_.EmailAddresses -join ","}}, OrganizationalUnit, @{n="ManagedBy";e={$_.ManagedBy | Foreach {(Get-Recipient $_).PrimarySMTPAddress}}}, LegacyExchangeDN, DistinguishedName | Export-Csv "DLs _$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv" -NoTypeInformation  
    

    Result:
    152066-57.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.