[ACCEPTED]-Get Groups From OU using DirectoryServices.AccountManagement-directoryservices
Accepted answer
You can set the PrincipalContext
to the OU where you want 2 to start the search and use the PrincipalSearcher
-class in 1 System.DirectoryService.AccountManagement
to accomplish what you need, like this:
PrincipalContext yourOU = new PrincipalContext(ContextType.Domain, "mycompany.local", "OU=Marketing,OU=Operations,OU=Applications,DC=mycompany,DC=local");
GroupPrincipal findAllGroups = new GroupPrincipal(yourOU, "*");
PrincipalSearcher ps = new PrincipalSearcher(findAllGroups);
foreach(var group in ps.FindAll())
{
Console.WriteLine(group.DistinguishedName);
}
Console.ReadLine();
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.