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. Get all users from a group in ad using directorysearcher

Get all users from a group in ad using directorysearcher

Scheduled Pinned Locked Moved C#
comquestion
1 Posts 1 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

    how do i change the filter to only give me users in my group i tryied memberOf='CN=GMDPortal,OU=IT,OU=ADM,DC=corp,DC=com' but it does not work i need to use a directorysearcher because i need to set search.PageSize = 4000; i have 3,000 users in this group public static ArrayList GetAllADDomainUsers() { string domainpath = @"LDAP://DC=corp,DC=com"; ArrayList allusers = new ArrayList(); DirectoryEntry searchRoot = new DirectoryEntry(domainpath); DirectorySearcher search = new DirectorySearcher(searchRoot); search.Filter = "(&(objectCategory=person)(objectClass=user)(memberOf='CN=GMDPortal,OU=IT,OU=ADM,DC=corp,DC=com' )(!userAccountControl:1.2.840.113556.1.4.803:=2))"; search.PropertiesToLoad.Add("samaccountname"); search.PropertiesToLoad.Add("distinguishedName"); search.PropertiesToLoad.Add("description"); search.PropertiesToLoad.Add("displayName"); search.PropertiesToLoad.Add("pwdLastSet"); search.PropertiesToLoad.Add("whenChanged"); search.ReferralChasing = ReferralChasingOption.All; search.PageSize = 4000; SearchResult result; SearchResultCollection resultCol = search.FindAll(); user ousr = new user(); if (resultCol != null) { for ( int counter = 0; counter < resultCol.Count; counter++) { result = resultCol[counter]; if (result.Properties.Contains("distinguishedName")) { ousr = new user(); ousr.dn = (string)result.Properties["distinguishedName"][0]; try { ousr.Description = (string)result.Properties["description"][0]; } catch (Exception er) { ousr.Description = " "; } try { ousr.DisplayName = (string)result.Properties["displayName"][0]; } catch (Exception er) { ousr.DisplayName = (string)result.Properties["samaccountname"][0]; } try

    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