I need a function to recursively get all groups names a specified user (as function argument) is a member of. The Function header should look like this where SAMAccountName
is the Username I want to get the groups from:
public List<string> GetUsersGroups(string SAMAccountName);
I hope you can help me.
Thanks in advance.
I'm assuming your problem is active directory side knowledge, not c#.
Basically task is ldap action, but I'll give examples using adfind that is quick and handy tool to output ldap queries to csv file for example. Functions you have to create by yourself.
There are 2 functions you need:
Function 1, find DN from samaccountname: adfind -dsq -f samaccountname=username
Function 2, find groups, including nested ones: adfind -f "(member:1.2.840.113556.1.4.1941:=CN=USERDN,OU=USERS,DC=DOMAIN,DC=COM)" samaccountname -list
Please find adfind syntax from joeware website: http://www.joeware.net/freetools/tools/adfind/usage.htm
For nested groups, more information: http://msdn.microsoft.com/en-us/library/aa746475(v=vs.85).aspx https://social.technet.microsoft.com/Forums/scriptcenter/en-US/f238d2b0-a1d7-48e8-8a60-542e7ccfa2e8/recursive-retrieval-of-all-ad-group-memberships-of-a-user?forum=ITCG