Fetch DL Information

Glenn Maxwell 11,096 Reputation points
2022-03-28T20:02:34.767+00:00

Hi All

i am using exchange 2016 hybrid environment. I have DLs created in onprem and online, I also have office365 unified groups. All my users are created in exchange onprem and they are migrated to cloud. i have a 100 users in CSV file and i want to know , are they owners of any DL either it be onprem, online or unified groups. i want to try something like this but not sure.
experts guide me.

My csv file is in the below format.

Name
user1@Company portal .com
user2@Company portal .com

$musers=import-csv "C:\temp\userlist.csv "  
$musers.Count  
$mgroups = @()  
Get-UnifiedGroup -ResultSize Unlimited |  
foreach-object {  
$dgroup=$_  
foreach($user in $musers) {  
if($dgroup.ManagedBy -contains $user.Name) {  
$mgroups += $dgroup  
$mgroups.Count }}}  
$mgroups | Select-Object DisplayName,PrimarySMTPAddress,Notes,@{label="ManagedBy";expression={[string]($_.managedby | foreach {$_.tostring() + ","})}} | Export-Csv "c:\temp\unifiedgroups.csv" -NoTypeInformation  
--------------------------------------------------------------------  
$musers=import-csv "C:\temp\userlist.csv "  
$musers.Count  
$mgroups = @()  
Get-DistributionGroup -ResultSize Unlimited |  
foreach-object {  
$dgroup=$_  
foreach($user in $musers) {  
if($dgroup.ManagedBy -contains $user.Name) {  
$mgroups += $dgroup  
$mgroups.Count }}}  
$mgroups | Select-Object DisplayName,PrimarySMTPAddress,Notes,@{label="ManagedBy";expression={[string]($_.managedby | foreach {$_.tostring() + ","})}} | Export-Csv "c:\temp\DistributionLists.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,473 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,582 questions
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,256 Reputation points
    2022-03-29T02:54:35.993+00:00

    @Glenn Maxwell

    For Office 365, you could use the script below to check it:

    $musers = import-csv "C:\temp\userlist.csv"  
    $groups = Get-UnifiedGroup -ResultSize Unlimited  
    $Data = @()  
      
    foreach ($muser in $musers) {  
        foreach($group in $groups){          
            if ($group.ManagedBy -contains (Get-Mailbox $muser.Name).Name){  
                $Data += Get-UnifiedGroup $group.name | select DisplayName,PrimarySMTPAddress,Notes,managedby  
            }  
        }     
    }  
    $Data | Export-Csv C:\temp\unifiedgroups.csv -NoTypeInformation  
    

    For distribution group, you could use the script below to check:

    $musers = import-csv "C:\temp\userlist.csv"  
    $groups = Get-DistributionGroup -ResultSize Unlimited  
    $Data = @()  
      
    foreach ($muser in $musers) {  
        foreach($group in $groups){          
            if ($group.ManagedBy -contains (Get-Mailbox $muser.Name).Name){  
                $Data += Get-DistributionGroup $group.name | select DisplayName,PrimarySMTPAddress,Notes,managedby  
            }  
        }     
    }  
    $Data | 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 additional answers

Sort by: Most helpful

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.