Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. // Declare new DirectoryEntry and DirectorySearcher
  2. DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
  3. string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
  4. DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);
  5.  
  6. // Set the properties of the DirectorySearcher
  7. dsSearch.Filter = "(objectClass=Computer)";
  8. dsSearch.PropertiesToLoad.Add("whenCreated");
  9. dsSearch.PropertiesToLoad.Add("description");
  10. dsSearch.PropertiesToLoad.Add("operatingSystem");
  11. dsSearch.PropertiesToLoad.Add("name");
  12.  
  13. // Execute the search
  14. SearchResultCollection computersFound = dsSearch.FindAll();
  15.  
  16. SortOption sortedResults = new SortOption("whenCreated", SortDirection.Descending);
  17. dsSearch.Sort = sortedResults;
  18.  
  19. public class SearchResultComparer : Comparer<SearchResult>
  20. {
  21. public override int Compare(SearchResult x, SearchResult y)
  22. {
  23. //Compare two SearchResult instances by their whenCreated property
  24. }
  25. }
  26.  
  27. List<SearchResult> SearchResultList = new List<SearchResult>(computersFound);
  28. SearchResultList.Sort(new SearchResultComparer());
  29.  
  30. new DirectorySearcher(entry)
  31. {
  32. Sort = new SortOption("cn", SortDirection.Ascending),
  33. PropertiesToLoad = {"cn"}
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement