AD Group Membership Export to File

I need to export the members of a distribution list within AD to a file.
I can see it can be done and has been posted before, but I can't seem to get the syntax right for my situation.

I need the contents of the DL called Coins Users
which is in (from the root) \UK\Distribution Lists\

Any advice?
I can see there is either a VBScript, or dsget
LVL 1
Stuart OramIT Technician - Project SitesAsked:
Who is Participating?
 
Mike KlineConnect With a Mentor Commented:
download the latest version of adfind (what I like using)
http://www.joeware.net/freetools/tools/adfind/index.htm
Then run this command
adfind -default -f name="coins users" -dsq | adfind -s base -asq member samaccountname
I created a "coins users" group in my lab and put one user in it to test the command (see screenshot)
Thanks
Mike

coinsusers.jpg
0
 
JDominguezNYCommented:
If the objects are all directly in the Coin Users OU and not subdivided you can just right click that OU and choose Export List.

You will be able to save the list of all objects in that OU as a text file.
0
 
Mike KlineConnect With a Mentor Commented:
Follow up to export it use
adfind -default -f name="coins users" -dsq | adfind -s base -asq member samaccountname -csv > c:\coinsusers.csv
will save a csv file on your c drive called coinsusers.csv
Thanks
Mike
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
JoemonkeyConnect With a Mentor Commented:
I use this vbscript, just change PUTDOMAINHERE to whatever your domain is, and change the file path/name if you want.  When you run this script it will prompt you for the user's samaccountname
'~~Script~~.
Option Explicit
Dim Group
Dim GroupName
Dim GroupDomain
Dim Member
Dim w
Dim ws
 
const ForReading = 1
const ForWriting = 2
const ForAppending = 8
Const TristateFalse = 0
 
GroupDomain = "PUTDOMAINHERE"
GroupName = InputBox ("Group Name to list Members:","Enter GroupName")
  if GroupName = "" then
  wscript.quit
  end if
 
Set ws = CreateObject ("Scripting.FileSystemObject")
Set w = ws.OpenTextFile ("C:\temp\" & GroupName & " members.txt",ForAppending, True)
 
Set Group = GetObject("WinNT://" & GroupDomain & "/" & GroupName & ",group")
 
For Each Member in Group.Members
  w.WriteLine Member.Name
Next
Wscript.Echo "Text file C:\temp\" & GroupName & " members.txt contains the list of users in this group."

Open in new window

0
 
JoemonkeyConnect With a Mentor Commented:
In my above comment:

it will prompt you for the user's samaccountname

should read

it will prompt you for the AD group name

Sorry :)
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Gave the most points to the one I used, but split points as appreciation of other posted solution!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.