public static Dictionary<string, string> SearchADInfo(string adName) { string strTemp = "LDAP://xxx.xxx.com"; DirectoryEntry entry = new DirectoryEntry(strTemp, ADUserName, ADPassword); entry.AuthenticationType = AuthenticationTypes.Secure; entry.RefreshCache(); var src = new System.DirectoryServices.DirectorySearcher(entry); //(SAMAccountName=" + adName + ") src.Filter = "(SAMAccountName=" + adName + ")"; src.PageSize = 10000;// 此参数可以任意设置,但不能不设置,如不设置读取AD数据为0~999条数据,设置后可以读取大于1000条数据。 var result = src.FindOne(); var ret = new Dictionary<string, string>(); var de = result.GetDirectoryEntry(); foreach (DictionaryEntry obj in result.Properties) { var value = string.Empty; foreach (Object obj2 in (ResultPropertyValueCollection)obj.Value) { value += obj2.ToString(); } ret.Add(obj.Key.ToString(), value.ToString()); } return ret; } }