Fetch DL owner information

Roger Roger 6,471 Reputation points
2022-03-30T22:04:24.553+00:00

Hi All

i have a DL lets say mydl@Company portal .com and it has members, i want to know these members are owners to how many other DLs. i am using the below syntax but i am not getting output

$DL1 = Get-DistributionGroupMember -ResultSize unlimited "MYDL@contoso.com"  
$DLs = Get-DistributionGroup -ResultSize unlimited  
$Results = @()  
  
foreach ($DL1 in $DLs) {  
   if ($DL1.ManagedBy -in $MYDL.name) {$Data += $DL | Select DisplayName,PrimarySMTPAddress,ManagedBy,Description}  
   else {}  
}  
  
$Results | Export-Csv C:\temp\output.csv -NoTypeInformation   
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,628 questions
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,704 questions
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,271 Reputation points
    2022-03-31T06:19:07.463+00:00

    @Roger Roger

    There are a lot of errors in it, you could compare with this one:

    $DL1S = Get-DistributionGroupMember "MYDL@contoso.com" -ResultSize unlimited   
    $DL2S = Get-DistributionGroup -ResultSize unlimited  
    $Result = @()  
         
    foreach ($DL1 in $DL1S) {  
        foreach($DL2 in $DL2S){          
            if ($Dl2.ManagedBy -contains $DL1.Name){  
                $Result += Get-DistributionGroup $DL2.name | select DisplayName,PrimarySMTPAddress,Notes,managedby  
            }  
        }     
    }  
    $Result | Export-Csv c:\temp\DistributionLists.csv -NoTypeInformation  
    

    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.


    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Amit Singh 4,986 Reputation points
    2022-04-01T11:14:30.38+00:00

    Try this script

    $myDisabledUsers = @()
    $date = get-date -format dd-MM-yyyy
    $managedSydGroups = Get-ADGroup -Filter * -Properties * -Searchbase "OU=SydExchangeGroups,OU=SydGroups,OU=Sydney,DC=my,DC=biz,DC=org" | where {$_.managedby -ne $null} | select name, managedby
    $disabledSydUser = Get-ADUser -Filter * -SearchBase "OU=SydDisabledUsers,OU=SydMisc,OU=Sydney,DC=my,DC=biz,DC=org" | where {$_.enabled -eq $false} | select -ExpandProperty distinguishedname
    
    $disabledOwners = foreach($group in $managedSydGroups)
    {
        $managedByString = [string]$group.managedby
        if($disabledSydUser -contains $managedByString)
        {$myDisabledUsers += $group} 
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.