Hi @Roger Roger,
Please add echo output, the full command is as follows:
$DLName = ”dl1@contoso.com"
$DistributionGroups= Get-DistributionGroup -ResultSize Unlimited | where { (Get-DistributionGroupMember $_.Name | foreach {$_.PrimarySmtpAddress}) -contains "$DLName"}
echo $DistributionGroups
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.