AD Group Membership Export to File

Posted on 2009-04-21
Last Modified: 2013-12-24
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
Question by:Stuart Oram
    LVL 4

    Expert Comment

    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.
    LVL 57

    Accepted Solution

    download the latest version of adfind (what I like using)
    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)

    LVL 57

    Assisted Solution

    by:Mike Kline
    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
    LVL 1

    Assisted Solution

    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
    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
      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
    Wscript.Echo "Text file C:\temp\" & GroupName & " members.txt contains the list of users in this group."

    Open in new window

    LVL 1

    Assisted Solution

    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 :)
    LVL 1

    Author Closing Comment

    by:Stuart Oram
    Gave the most points to the one I used, but split points as appreciation of other posted solution!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
    Read about achieving the basic levels of HRIS security in the workplace.
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now