Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Active directory Users

Active directory Users

Scheduled Pinned Locked Moved C#
comwindows-adminhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    caiena
    wrote on last edited by
    #1

    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; }

    M 1 Reply Last reply
    0
    • C caiena

      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; }

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups