Hi @Roger Roger
Did you mean Microsoft 365 group when you say office365 unified group?
If yes, Microsoft 365 Groups don't support nesting with other Microsoft 365 Groups or with distribution or security groups.
To get the members in DL and nested DLs, would the following script work for you:
# Exporting DL Objects
Get-DistributionGroupMember -Identity DL1 | where {$_.RecipientType -eq 'UserMailbox'} |Select-Object name, WindowsLiveID | Export-Csv "C:\scripts\mailbox_in_DG.csv"
#Export Only DL Names from the Parent Group
Get-DistributionGroupMember -Identity DL1 | where {$_.RecipientType -ne 'UserMailbox'} | Select-Object name | Export-Csv "C:\scripts\nestedDG.csv"
# Exporting Nested DL Objects With individual File
Import-Csv "C:\scripts\nestedDG.csv" |
foreach{
Get-DistributionGroupMember -Identity $_.Name | Select-Object name, WindowsLiveID | Export-Csv -Path C:\scripts\"$($_.Name)".csv -NoTypeInformation
}
In mailbox_in_DG.csv you would see normal user mailboxes in this DL.
In nestedDG.csv you would see names of nested DLs in this DL.
It would also output the membership of the nested DLs in the csv files which are named in the format <nested DL name>.csv.
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.