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