Posted by: Andy Grogan | July 25, 2007

Get Distribution List Membership and attributes to a CSV file

Yesterday I answered a question on the MSExchange forums about how you can retrieve the membership of a Distribution list to a file and thought that it might make a good subject for a blog.

At first I told the person that without programming the simplest way if to jump on to a Domain Controller in the domain that Exchange lives and type the following command:

net group “Name of Dist List” >c:\dist.txt

The person came back to me and said that although that worked for full users it didn’t give the membership of contacts – nor provide the e-mail addresses of the members.

I decided to write a little script that could accomplish the task and the following is what I came up with:

In order to use this script – copy it to your Exchange server, double click on it and type in the Directory path to your group in the box that appears – for example a valid Directory path would be: CN=MyDist,OU=DistLists,DC=MyDomain,DC=Com

On Error Resume Next

strPath = inputbox(“Please enter in the path to your group in AD”)

Set objGroup = GetObject (“LDAP://” & strPath)

objGroup.GetInfo

strArrMember = objGroup.GetEx(“member”)

dim fs,objWriteFile

set fs=CreateObject(“Scripting.FileSystemObject”)

set objWriteFile = fs.CreateTextFile(“GrpMem.csv”, True)

dim objDistinguishedName

objWriteFile.Write “FullName,Sam Account,e-Mail” & vbcrlf

For Each strMember in strArrMember

Set objUser = GetObject (“LDAP://” & strMember) objWriteFile.Write objUser.FullName & “,” & objUser.sAMAccountName & “,” & objuser.mail & vbcrlf


Leave a response

Your response:

Categories