Ldap – Extract list of users in a set of nested AD groups

active-directoryldap

I need to get a list of all of the users who are ultimately members of an active directory group. There's a single parent group which has a few other groups as its members, and each of those groups have a few users and several other groups as members in turn.

I need to extract:

  • First Name
  • Last Name
  • AD Username

From every user who is a member (directly or indirectly) of the top level group. It feels like this should be possible with dsquery, but I've only limited experience and can't figure out the syntax. It also should be possible using a DirectorySearcher in the System.DirectoryServices .Net namespace, but my LDAP isn't quite good enough!

Any suggestions on how to proceed with either approach would be much-appreciated.

Many thanks,
Jon

Best Answer

Ok, well I've used this Powershell script to do this a number of times, it produces a listing of all users and groups under the group you specify. Obviously it can be tailored to give you the output you want.

You can use the export-csv command to then get your output into a CSV file.