Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, "domainname", "username", "password")); Forest forest = domain.Forest; DomainCollection domains = forest.Domains;
List<string> lstName = new List<string>(); DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://DC=domainname,DC=com", "username", "password"); DirectorySearcher oDirectorySearcher = new DirectorySearcher(directoryEntry,"(objectCategory=organizationalUnit)", null); SearchResultCollection oSearchResultCollection = oDirectorySearcher.FindAll(); foreach (SearchResult item in oSearchResultCollection) { string name = item.Properties["name"][0].ToString(); lstName.Add(name); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)