Active directory Users
-
i user this code to get all users on the domain but it only returns me 1,000 users the problem is i have over 3,000 users in my domain what can i do to get the entire user list from AD public static ArrayList GetAllADDomainUsers() { string domainpath = @"LDAP://DC=tshospital,DC=com"; ArrayList allUsers = new ArrayList(); DirectoryEntry searchRoot = new DirectoryEntry(domainpath); DirectorySearcher search = new DirectorySearcher(searchRoot); search.Filter = "(&(objectClass=user)(objectCategory=person))"; search.PropertiesToLoad.Add("samaccountname"); SearchResult result; SearchResultCollection resultCol = search.FindAll(); if (resultCol != null) { for (int counter = 0; counter < resultCol.Count; counter++) { result = resultCol[counter]; if (result.Properties.Contains("samaccountname")) { allUsers.Add((String)result.Properties["samaccountname"][0]); //allUsers.Add(result.GetDirectoryEntry()); } } } return allUsers; }
-
i user this code to get all users on the domain but it only returns me 1,000 users the problem is i have over 3,000 users in my domain what can i do to get the entire user list from AD public static ArrayList GetAllADDomainUsers() { string domainpath = @"LDAP://DC=tshospital,DC=com"; ArrayList allUsers = new ArrayList(); DirectoryEntry searchRoot = new DirectoryEntry(domainpath); DirectorySearcher search = new DirectorySearcher(searchRoot); search.Filter = "(&(objectClass=user)(objectCategory=person))"; search.PropertiesToLoad.Add("samaccountname"); SearchResult result; SearchResultCollection resultCol = search.FindAll(); if (resultCol != null) { for (int counter = 0; counter < resultCol.Count; counter++) { result = resultCol[counter]; if (result.Properties.Contains("samaccountname")) { allUsers.Add((String)result.Properties["samaccountname"][0]); //allUsers.Add(result.GetDirectoryEntry()); } } } return allUsers; }
You have to perform a paged seach, you can't exceed the server side limit of 1000 objects returned. See DirectorySearcher.PageSize [^]property.
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.