List all Distribution Groups and their Membership in Office 365

This script will export all users and their Distribution Group membership from Office 365 to a CSV file which you can manipulate in Excel.

 
 
 
 
 
4.8 Star
(59)
53,960 times
Add to favorites
Office 365
3/3/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Show users with no groups
    2 Posts | Last post July 26, 2019
    • Is there a quick edit to show all users even if they belong to no groups?  My goal is to audit and find any of my ~600 users that had been left out of needed groups.
    • I'd like to know that as well
  • Get O365 group members as well
    1 Posts | Last post July 26, 2019
    • Below can be added to the script to get results of O365 group
      
      {   
              #Getting all the Office 365 Groups in the tenant        
              Write-Host "Getting all the members for each O365 Group in the tenant ..." -foregroundcolor Green    
              $O365Groups=Get-UnifiedGroup
              # Deleting the users
              Write-Host "Getting all the users per Group ..." -ForegroundColor Green    
              foreach ($O365Group in $O365Groups) 
              { 
                  Write-Host "Members of Group: " $O365Group.DisplayName -ForegroundColor Green
                  Get-UnifiedGroupLinks –Identity $O365Group.Identity –LinkType Members
                  Write-Host
              } 
          }
          catch [System.Exception]
          {
              Write-Host -ForegroundColor Red $_.Exception.ToString()   
          } 
  • Export only groups with 0 members
    2 Posts | Last post May 24, 2019
    • Is it possible to modify this to show groups with zero members? I am trying to weed out groups that no longer have members assigned. 
    • If anyone is searching for this same question, below script might help you.
       - You can export empty groups.ie, Group without members
       - You can export groups based on member count. ie, Group that has more than 50 members
      
      https://gallery.technet.microsoft.com/Export-Office-365-811ad3a2
  • How to display only certain distribution lists?
    2 Posts | Last post May 24, 2019
    • I didn't want my CSV to contain all of the distribution lists.
      
      I changed this:
      
      #Get all Distribution Groups from Office 365 
      $objDistributionGroups = Get-DistributionGroup -ResultSize Unlimited 
      
      
      To this to display only 3 specific distribution lists:
      
      #Get all Distribution Groups from Office 365 
      $objDistributionGroups = Get-DistributionGroup -ResultSize Unlimited -filter {name -like "staff" -or name -like "faculty" -or name -like "students"}
      
      
      I hope this helps someone.
    • Instead of filtering(because it will get all DL and then check for filtering), you can use an input file that contains a particular distribution group alone. Below script accepts input file to get single/specific distribution group membership. 
      https://gallery.technet.microsoft.com/Export-Office-365-811ad3a2
  • Can you make it work with EXO PowerShell for MFA enabled admins?
    2 Posts | Last post May 23, 2019
    • We have MFA enabled on admin accounts, need help in making this script work MFA enabled accounts:
      https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps
      
    • I'd suggest you to try below script which works with MFA enabled account
      
      http://o365reports.com/2019/05/23/export-office-365-distribution-group-members-csv/
  • Dynamic Distribution Groups?
    2 Posts | Last post May 23, 2019
    • Is there a way to adapt this script to list the members of a dynamic distribution group?
    • This script cannot be altered to list Dynamic Distribution Group members as it needs different cmdlets like Get-DynamicDistributionGroup, Get-Recipient. You can use scripts that already available in the TechNet gallery. E.g., https://gallery.technet.microsoft.com/office/Export-Office-365-Dynamic-7f66e229
  • can we use managed by in your script
    2 Posts | Last post May 23, 2019
    • Hi it is excellent script but can we use for getting owner of the distribution group and 
      we had issue of ordering with member display name it not match with output 
       can we use this attribute
      $($objDistributionGroup.managedby)
      in your query for get result.
    • Alan already has done a great job, but it's not updated for a while. We have worked on a script to adopt more customization and attributes which includes Distribution group owner too. You can download the script here: https://gallery.technet.microsoft.com/Export-Office-365-811ad3a2
  • Where is the output file located?
    4 Posts | Last post July 20, 2018
    • I cant find the file after complete running the command.
    • You'll most likely find it in C:\Windows\SysWOW64\DistributionGroupMembers.csv
    • I did a search *.csv for the file in C: and found it in the same folder as I ran the script from. BTW, thanks for this powerful script guys, this is awesome.
    • download the ps1 file and save it to other location e.g D:\output 
      Navigate the PowerShell to d:\output and then run the script from there.
      The result will be exported at D:\output :)
      
  • Environment for this to work ?
    1 Posts | Last post July 06, 2018
    • Hi
      Is this script meant to work out of the box ? I would have assumed yes because is does a remote powershell session?
      Or is some module - software needed to be installed ?
      Context: Running on an end user machine, no exchange installed.
      
      I get "Get-DistributionGroup : The term 'Get-DistributionGroup' is not recognized as the name of a cmdlet, function, script file, 
      or operable program."
      
      (debug shows the #Session seems to be valid)
      
      Thanks
  • how to use csv file list of DL
    2 Posts | Last post May 09, 2018
    • Is there a way to use a csv file list of DL's rather than pump it out for all the DL's in a tenant? Situation is migrating one domain from an existing tenant to a new tenant due to company separation, so rather than get the whole lot from all 5 domains I just need the list for the one domain that is migrating. 
      
      Get-DistributionGroup -Filter {EmailAddresses -like "smtp:*@<domain>" } doesn't work for me.
    • running this script in MSOL right? It works like a charm for me giving me a CSV output without modifying anything in the PS script. AS the title says: "This script will export all users and their Distribution Group membership from Office 365 to a CSV file which you can manipulate in Excel."
1 - 10 of 43 Items