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.
Export DL owners in smtp formt
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
2 answers
Sort by: Most helpful
-
-
Kael Yao-MSFT 37,496 Reputation points Microsoft Vendor
2021-11-24T06:15:15.197+00:00 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:
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.