Link to home
Create AccountLog in
Avatar of abaskett
abaskett

asked on

Export Distribution List Members (including contacts) from AD to Excel

I am looking for a VBScript to export all the members - (including contacts) of a distribution list to Excel or txt file. I have found scripts that get me most of the way there by giving me a list of users without contacts. Any help would be greatly appreciated.

Here's an example of a script I've been using:
Dim objGroup, objUser, objFSO, objFile, strDomain, strGroup, Domain, Group
'Change DomainName to the name of the domain the group is in
strDomain = Inputbox ("Enter the Domain name", "Data needed", "Default domain name")
'Change GroupName to the name of the group whose members you want to export
strGroup = InputBox ("Enter the Group name", "Data needed", "Default group name")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'On the next line change the name and path of the file that export data will be written to.
Set objFile = objFSO.CreateTextFile("C:\" & strGroup & " - Members.txt")
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
For Each objUser In objGroup.Members
    objFile.WriteLine objUser.Name & " - " & objUser.Class
Next
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objUser = Nothing
Set objGroup = Nothing
Wscript.Echo "Done"
Wscript.Echo "Please check the c: for your output file"
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

Just run this at a command prompt, no need for vb
csvde -e -f filename -s servername -r "(sAMAccountName=MyGroup) -d "OU=ObjectOU,DC=domainname,DC=local"

Open in new window

oops, forgot to close quote...
csvde -e -f filename -s servername -r "(sAMAccountName=MyGroup)" -d "OU=ObjectOU,DC=domainname,DC=local"

Open in new window

...missed another switch :(
csvde -e -f filename -s servername -r "(sAMAccountName=MyGroup)" -l members -d "OU=ObjectOU,DC=domainname,DC=local"

Open in new window

Avatar of abaskett
abaskett

ASKER

Thank you! I have no experience using CSVDE. Would it look something like this when I run it?

csvde -e -f ADExport.csv -s Bigserver -r "(sAMAccountName=All Regional VPs)" -l members
ASKER CERTIFIED SOLUTION
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
That worked perfectly! Thank you!