Pin Me

How to Extract a List of Exchange Distribution Groups with Associated Members

written by: •edited by: Lamar Stonecypher•updated: 6/18/2009

As a Domain or Exchange administrator, you will at some point be asked what distribution groups you have and who the members are of those groups. This article will show you how to extract all mail distribution groups along with their associated group manager and group members.

  • slide 1 of 3

    The Script

    If you don’t already have an enterprise solution in place such as Quest MessageStats that will give you detailed reporting on your Exchange groups, you may struggle to find a way to extract groups and group membership. This article will show you how to do this using a great script from Bharat Suneja of the Exchangepedia blog.

    The script we're going to use will give us the following attributes for each group -

    • Group Name
    • Group Type (distribution or security)
    • Description
    • Group Owner
    • Group Members
  • slide 2 of 3

    Obtain and use the script

    Before proceeding, you’ll need to make sure you are going to run the script from a computer that is part of the domain you are querying and that you have Exchange or Domain Administration permissions for your domain.

    Go here to get the script. Download it and unzip it to a folder on your computer.

    You can run the script without making any modifications –

    1. Go to a command prompt and navigate to the directory with your script.
    2. Type the following “cscript listdistgroups.vbs /f: c:\outputfile.csv”. This will create a CSV formatted file called “outputfile.csv” on your root C:\ drive.

    The default output is great, but will require you to go into Excel to split up the columns (using the Text to Columns feature). This will be useful for those of you who need to play around with the data – sorting, filtering etc, but what if you just want a quick and dirty text file listing the groups? Keep reading.

    For more information on how to convert text to columns, read this article.

    CSV 

  • slide 3 of 3

    Modify the script for plain text output

    In order to display the output in a nice plain text format as shown in the picture below, you’ll need to edit the script with Notepad. Do a search for the first line “original” and replace it with the second line displayed. Save the file as a new name and you should be good to go.

    • Original: strFirstLine = strFirstLIne & I & "#" & objGroup.sAMAccountName & " # "
    • Replace with: strFirstLine = strFirstLIne & vbCrLf & "--------" & vbCrLf & I & " " &objGroup.sAMAccountName & vbCrLf & "--------" & vbCrLf

    • Original: strFirstLine = strFirstLIne & "Security Group" & "#"
    • Replace with: strFirstLine = strFirstLIne & "Type: Security Group" & vbCrLf

    • Original: strFirstLine = strFirstLIne & "Distribution Group" & "#"
    • Replace with: strFirstLine = strFirstLIne & "Type: Distribution Group" & vbCrLf

    • Original: strFirstLine = strFirstLine & strDescription & "#"
    • Replace with: strFirstLine = strFirstLine & "Description: " & strDescription & vbCrLf

    • Original: 'Wscript.Echo "This group does not have a Manager."
    • Replace with: 'Wscript.Echo "Manager: This group does not have a Manager."

    • Original: strFirstLine = strFirstLine & "No Manager" & "#"
    • Replace with: strFirstLine = strFirstLine & "Manager: No Manager Assigned" & vbCrLf

    • Original: strFirstLine = strFirstLine & strManagerName & "#"
    • Replace with: strFirstLine = strFirstLine & "Manager: " & strManagerName & vbCrLf

    • Original: strFirstLine = strFirstLIne & "---NONE---"
    • Replace with: strFirstLine = strFirstLIne & "NO MEMBERS" & vbCrLf & vbCrLf

    • Original: 'strFirstLine = strFirstLIne & VbCrlf & "Members: "
    • Replace with: strFirstLine = strFirstLIne & VbCrlf & "Members: " & vbCrLf

    • Original: strFirstLine = strFirstLIne & objUser.displayName & ","
    • Replace with: strFirstLine = strFirstLIne & objUser.displayName & vbCrLf

    Plain Text Output 

    Summary

    With a few minutes of your time, you’ll have a powerful and free solution to find how many groups you have, who owns them, and who is a part of any given group for your domain.