Export a list of members from an Active Directory group to a text file

I needed to export a list of all the members in an active directory group today. Here are two methods which work well. The first example uses the net group command. In both examples ‘Group Name’ is the name of the group that you want to export the member list for, and memberlist.txt is the name of the output file.

net group “Group Name” /domain > memberlist.txt

The second example uses dsquery and dsget, which will return the full distinguished names of the user objects that are members of the group. This could be useful if you also need to know which organizational unit the members accounts reside in.

dsquery group -name “Group Name” | dsget group -members > memberlist.txt

20 Responses to Export a list of members from an Active Directory group to a text file

  1. keith Rosenberg's avatar keith Rosenberg says:

    So how do I get a list of all groups and their members?

  2. Paul's avatar Paul says:

    are running this script in this in cmd?

  3. emnavarro02's avatar emnavarro02 says:

    Cool. This save some time. Thnx 😉

  4. Kitaab's avatar Kitaab says:

    Thanks It was useful

  5. David's avatar David says:

    This just saved me a ton of time. Thank you!

  6. Jonathan Rey's avatar Jonathan Rey says:

    Great! simple script. Best solution

  7. Worked great for me. Thank you

  8. Kaihan Arian's avatar Kaihan Arian says:

    Hi all; thanks it is too useful for me but i want know how i can export member of users with its descriptions so please help me …

  9. andrea's avatar andrea says:

    dsquery group -name “Group Name” | dsget group -members > memberlist.txt return a error….
    ..

    dsget failed:’Target object for this command’ is missing.

  10. Tony Trunkfield's avatar Tony Trunkfield says:

    Great script – and works fast.

  11. sachin's avatar sachin says:

    this command cant extract if the group has space between eg. sec audit team

  12. Subhankara Nayak's avatar Subhankara Nayak says:

    hi
    from this script we can only know the member name or logon name.
    can we get name with the mail id as well.??

  13. raudan's avatar raudan says:

    thanks 🙂
    it works 🙂 😉

  14. Jack's avatar Jack says:

    Where does the txt file reside once the script has run?

  15. Avinash Reddy's avatar Avinash Reddy says:

    Thank you very much. This saved my lot of time.

Leave a reply to Subhankara Nayak Cancel reply