c# - List all group of AD and Organizational Unit -


i using following code groups of activedirectory.

public static task<list<string>> getgroups(string domain = "")     {         return (task.factory.startnew<list<string>>(() =>         {             list<string> list = new list<string>();             try             {                 if (string.isnullorwhitespace(domain))                 {                     selectquery squery = new selectquery("win32_group", "localaccount=\"true\"");                     managementobjectsearcher msearcher = new managementobjectsearcher(squery);                     list.addrange(msearcher.get().cast<managementobject>().select(x => x["name"].tostring()));                 }                 else                 {                     directoryentry directoryentry = new directoryentry("ldap://" + domain);                      directorysearcher searcher = new directorysearcher(directoryentry, "(&(objectclass=group))");                     searcher.searchscope = searchscope.subtree;                     list.addrange(searcher.findall().cast<searchresult>().select(x => x.getdirectoryentry().name.replace("cn=", string.empty)));                 }             }             catch (comexception e)             {                 logger.writeexception(e);             }             return (list.orderby(x => x).tolist());         }));     } 

the code works dit not return groups declared in organizational unit... how can group including ou ?

thanks in advance


Comments