Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Declare new DirectoryEntry and DirectorySearcher
- DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
- string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
- DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);
- // Set the properties of the DirectorySearcher
- dsSearch.Filter = "(objectClass=Computer)";
- dsSearch.PropertiesToLoad.Add("whenCreated");
- dsSearch.PropertiesToLoad.Add("description");
- dsSearch.PropertiesToLoad.Add("operatingSystem");
- dsSearch.PropertiesToLoad.Add("name");
- // Execute the search
- SearchResultCollection computersFound = dsSearch.FindAll();
- SortOption sortedResults = new SortOption("whenCreated", SortDirection.Descending);
- dsSearch.Sort = sortedResults;
- public class SearchResultComparer : Comparer<SearchResult>
- {
- public override int Compare(SearchResult x, SearchResult y)
- {
- //Compare two SearchResult instances by their whenCreated property
- }
- }
- List<SearchResult> SearchResultList = new List<SearchResult>(computersFound);
- SearchResultList.Sort(new SearchResultComparer());
- new DirectorySearcher(entry)
- {
- Sort = new SortOption("cn", SortDirection.Ascending),
- PropertiesToLoad = {"cn"}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement