public ADGroupMember(string _distinguishedName) { ADObject = new ADObject(); ADObject.DistinguishedName = _distinguishedName; string _temp = ADObject.ActiveDirectoryEntry.SchemaClassName; switch (_temp) { case ("user"): this.Type = ADObject.ActiveDirectorySchemaClassEnum.user; ADObject.Name = ADObject.ActiveDirectoryEntry.Properties["sAMAccountName"].Value.ToString(); break; case ("group"): this.Type = ADObject.ActiveDirectorySchemaClassEnum.group; ADObject.Name = ADObject.ActiveDirectoryEntry.Properties["name"].Value.ToString(); break; case ("computer"): this.Type = ADObject.ActiveDirectorySchemaClassEnum.computer; ADObject.Name = ADObject.ActiveDirectoryEntry.Properties["name"].Value.ToString(); break; case ("contact"): this.Type = ADObject.ActiveDirectorySchemaClassEnum.contact; ADObject.Name = ADObject.ActiveDirectoryEntry.Properties["name"].Value.ToString(); break; } }
protected SearchResultCollection searchForADObjects(ADObject.ActiveDirectorySchemaClassEnum objectCls, string _searchTerm) { using (DirectoryEntry entry = _getDirectoryEntryWithAuthInternal(_activeDirectoryBasePathWithServer)) { using (DirectorySearcher mySearcher = new DirectorySearcher(entry)) { switch (objectCls) { case ActiveDirectorySchemaClassEnum.user: if (string.IsNullOrWhiteSpace(_searchTerm)) { mySearcher.Filter = "(&(objectCategory=person)(objectClass=user))"; } else { mySearcher.Filter = string.Format("(&(objectCategory=person)(objectClass=user)(sAMAccountName=*{0}*))", _searchTerm); } mySearcher.PropertiesToLoad.Add("sAMAccountName"); break; case ActiveDirectorySchemaClassEnum.contact: if (string.IsNullOrWhiteSpace(_searchTerm)) { mySearcher.Filter = "(&(objectCategory=person)(objectClass=contact))"; } else { mySearcher.Filter = string.Format("(&(objectCategory=person)(objectClass=contact)(name=*{0}*))", _searchTerm); } mySearcher.PropertiesToLoad.Add("name"); break; case ActiveDirectorySchemaClassEnum.group: if (string.IsNullOrWhiteSpace(_searchTerm)) { mySearcher.Filter = "((objectCategory=group))"; } else { mySearcher.Filter = string.Format("(&(objectCategory=group)(Name=*{0}*))", _searchTerm); } mySearcher.PropertiesToLoad.Add("Name"); break; case ActiveDirectorySchemaClassEnum.computer: if (string.IsNullOrWhiteSpace(_searchTerm)) { mySearcher.Filter = "((objectCategory=computer))"; } else { mySearcher.Filter = string.Format("(&(objectCategory=computer)(Name=*{0}*))", _searchTerm); } mySearcher.PropertiesToLoad.Add("Name"); break; } SearchResultCollection results = mySearcher.FindAll(); return(results); } } }