Distribution Group Import/Export

Administrators are frequently asked for a list of distribution groups and their memberships for a number of reasons (auditing, compliance, nosy bosses).  Here's a script that generates that output, one distribution group and member per line, which, can also serve as a great mak

2,837 times
Add to favorites
Office 365
E-mail Twitter del.icio.us Digg Facebook
  • When Exporting file, with -Manager it is not collecting correct info.
    1 Posts | Last post November 12, 2019
    • I am using ".\DistributionGroupImportExport.ps1 -Mode Export -Filename DistributionGroups.csv -Manager" to export the list of Group with manager but the report is showing as below 
      Please help.
  • What should I use for Migration with Members and Managed by property, I did not find the related ./Example for that?
    1 Posts | Last post November 11, 2019
    • I am trying to migrate 960 DLs, this script seems perfect however, I am not able to capture managedBy Some Reason I am not able to make it.
      I have to Import Groups with Members, and Owners of the group at once and then Export these value on Different tenant. 
      The problem is, All groups have multiple Owners and those are not getting captured with this script or may be I am not able to use this script properly. 
  • Delivery management config
    4 Posts | Last post May 24, 2019
    • I've used this script for a couple small migrations and it's worked overall pretty well. Looking at it for an upcoming migration though I don't see an option in this script to pull the delivery management options for internal/external capability. Is that something that can be easily added?
    • What features would you be looking for specifically? I'm always happy to add new features! The parameter I can think of off the top of my head:
      - RequireSenderAuthenticationEnabled [bool]
    • Aaron - so sorry! I got tied up in the project and ended up making some additions to the script myself. I was able to solve my original question and also add the capability to capture the manager of the group. 
      I'm no expert in PS and definitely had to do some weird things to accomplish my goal. Those are two features that would be great to be included in the script properly.
    • Aaron 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 manager and RequireSenderAuthenticationEnabled too. You can download the script here:
  • Issues with the script
    8 Posts | Last post December 11, 2018
    • First let me say this is a amazing script (Layout and use case), but the script does not work properly I've spent a lot of time trying to fix but no luck. 
      Initially I replaced the -notin with -notcontain and searching for a domain with filter doesn't work in a multi tenant environment.
      When importing to Office 365 with all distribustion groups it errors on x500 issues with no array of members. 
      If we can resolve this would be perfect for all migrations.  
    • Can you give me some examples with what you're doing?  I've run this in dozens of environments in the last year (starting with Exchange 2010 and up), so some information on what the errors are that you're seeing would be helpful.  Information to include:
      - Source environment (OS, Exchange Version, PowerShell Version, etc)
      - Target environment (OS, Exchange Version, PowerShell Version, etc)
      - Full command line being run
      - any screen errors or logs
      - sample of the output generated from the source environment
      If you'd like, you can email it to me directly at:
      aaron (dot) guilmette (at) microsoft (dot) com
    • Hi, we had the same issues with "-notin" and some others. I already e-mailed them to your mail. Just wondering if got the e-mail.
    • Can you let me know what version of PowerShell you're working with?  I'll update the script, but I want to find out what people are using so I can test against them.
    • Hi,
      First of all, let me say great job on the script and effort you did.
      However, I encountered few issues when using in my environment.
      What we do at the moment is cross forest migration of AD domains and exchange domain as well.
      The case was from exchange 2010 to exchange 2013.
      On the source we have powershell version 2:
      [PS] C:\Admin>$PSVersionTable
      Name                           Value
      ----                           -----
      CLRVersion                     2.0.50727.8762
      BuildVersion                   6.1.7601.17514
      PSVersion                      2.0
      WSManStackVersion              2.0
      PSCompatibleVersions           {1.0, 2.0}
      PSRemotingProtocolVersion      2.1
      On the destination server is version 4:
      [PS] C:\Admin>$PSVersionTable
      Name                           Value
      ----                           -----
      PSVersion                      4.0
      WSManStackVersion              3.0
      CLRVersion                     4.0.30319.42000
      BuildVersion                   6.3.9600.18773
      PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
      PSRemotingProtocolVersion      2.2
      On the source server we noticed the problem with the version and changed this lines (twice in the script):
      #If ($Group.PrimarySmtpAddress -notin $CheckGroupMembershipMember.PrimarySmtpAddress)
      With this
      If ($CheckGroupMembershipMember.PrimarySmtpAddress -notcontains $Group.PrimarySmtpAddress )
      Another hint for our special character used in names (Croatian - čćžšđČĆŽŠĐ) is to use „-encoding UTF8“ on the export-csv .
      After these changes the export functionality seems to work correctly for us.
    • The import was a bit more challenging since I'm not a powershell expert so I had to work on trial and error with google support.
      In the end I had to make the following changes to be able to import the exported groups with all the assigned proxy addresses:
      # Add the ProxyArray variable from the CSV input to the GroupToUpdate Email Addresses Array and leave only unique values
      $LegacyExchangeDN = "x500:"+$Group.legacyExchangeDN
      $ProxyArray += $LegacyExchangeDN
      $GroupToUpdate.EmailAddresses += $ProxyArray
      $GroupToUpdate.EmailAddresses = $GroupToUpdate.EmailAddresses | Sort -Unique
      Write-Log -Message "List of proxy addresses to be added to $($Group.DistributionGroup):" -WriteFile -EntryType Verbose
      Write-Log -Message "$($GroupToUpdate.EmailAddresses)" -WriteFile -EntryType Verbose
      Set-DistributionGroup -Identity $GroupToUpdate.PrimarySmtpAddress -EmailAddresses $GroupToUpdate.EmailAddresses
      Changed to this:
      # Add the ProxyArray variable from the CSV input to the GroupToUpdate Email Addresses Array and leave only unique values
      $LegacyExchangeDN = "x500:"+$Group.legacyExchangeDN
      #$ProxyArray += $LegacyExchangeDN
      #$GroupToUpdate.EmailAddresses += $ProxyArray
      $GroupToUpdate.EmailAddresses = $ProxyArray
      #$GroupToUpdate.EmailAddresses = $GroupToUpdate.EmailAddresses | Sort -Unique
      $GroupToUpdate.EmailAddresses = [String[]]$GroupToUpdate.EmailAddresses | Sort -Unique
      Write-Log -Message "List of proxy addresses to be added to $($Group.DistributionGroup):" -WriteFile -EntryType Verbose
      Write-Log -Message "$($GroupToUpdate.EmailAddresses)" -WriteFile -EntryType Verbose
      #Set-DistributionGroup -Identity $GroupToUpdate.PrimarySmtpAddress -EmailAddresses $GroupToUpdate.EmailAddresses
      Set-DistributionGroup -Identity $Group.DistributionGroup -EmailAddresses $GroupToUpdate.EmailAddresses
      After these changes the import was working as much as I can see.
      Maybe you'll figure out what was causing all this problems and change accordingly.
    • If you need more info or debug errors I will gladly redo some scenarios for you with more details.
      Best regards, 
    • Hello,
      'notin' is not available in PowerShell < 3, so it is not related to Exchange Management Shell.
      Maybe you can add '#Requires -Version 3' in the script ?
  • I get a blank csv when exporting :(
    1 Posts | Last post April 07, 2018
    • Trying to export to csv to get a template to use this seemingly great script you've kindly made in order to import to 365 using a list of distros and members.
      PS C:\Users\admin-agent\OneDrive\HME> .\DistributionGroupImportExport.ps1 -Mode Export -Filename DistributionGroups.csv
      Security warning
      Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
      computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
      message. Do you want to run C:\Users\admin-agent\OneDrive\HME\DistributionGroupImportExport.ps1?
      [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
      Total number of Distribution Groups Matching Filter: 2
      Procesing [1/2] All Employees ...
      Procesing [2/2] Test ...
      but the csv is blank
      Thanks for helping.