Monday, March 30, 2009

Enumerating Members of a Group (including Nested Groups)

Here's another simple and straightforward script that queries and enumerates the members of an active directory group. If there are nested groups within the groups being queried, these will also be subsequently checked and their members listed.

This is the main body of the script. I have, for this example, three sites where two groups are being queried (one group, for example, is EU-ServerAdmins-G). There is a call in the main body to the EnumGroups function where three parameters are passed - strSite, strDN and strGroupName).



The EnumGroups function queries the strDN parameter where its members are checked. In the Select-Case loop, the object class is further checked; if the object is a group by itself, the function executes again with this group as part of the parameters passed (hence, nested groups will also be queried).



The output of this script is written onto a file (groups.csv). An example output file would look like this:


No comments: