我正在访问Active Directory。如果我这样称呼它
DirectorySearcher srch = new DirectorySearcher(de);
//Filter to return only users and deleted users and not system accounts
srch.Filter = "(|(&(objectCategory=person)(objectClass=user)(sn=*))(&(isDeleted=TRUE)(objectClass=user)))";
srch.SearchScope = SearchScope.OneLevel;
srch.ExtendedDN = ExtendedDN.Standard;
srch.FindAll();
然后它返回一个包含一些属性的用户列表...我想看到“whenChanged”属性,但是当我尝试添加该行时
srch.PropertiesLoad.Add("whenChanged");
然后它不会返回任何用户。这可能是由于删除的用户没有该属性,并且它无法统一应用所有属性,因此返回0结果?如何查看已删除和活动的所有用户,并查看所有用户的“whenChanged”属性,即使它导致 null
答案 0 :(得分:1)
有几点:
srch.Tombstone = true;
DirectorySearcher.PropertiesLoad
的所有属性都不应删除任何结果
这可能是由于srch.PropertiesLoad.Add("whenChanged");
sn=*
放入搜索中?这会筛选出未设置姓氏的用户
这是打算吗?测试了以下代码,可以成功获取用户和已删除的用户,并获取“whenChanged”属性。请试一试。
DirectoryEntry de = new DirectoryEntry("LDAP://domain.com/dc=domain,dc=com", "user", "pwd");
DirectorySearcher srch = new DirectorySearcher(de);
//Filter to return only users and deleted users and not system accounts
srch.Filter = "(|(&(objectCategory=person)(objectClass=user)(sn=*))(&(isDeleted=TRUE)(objectClass=user)))";
srch.SearchScope = SearchScope.Subtree;
srch.ExtendedDN = ExtendedDN.Standard;
srch.Tombstone = true;
srch.PropertiesToLoad.Add("whenChanged");
srch.PropertiesToLoad.Add("distinguishedName");
using (SearchResultCollection results = srch.FindAll())
{
foreach (SearchResult result in results)
{
string dn = result.Properties["distinguishedName"][0] as string;
Console.WriteLine("- {0}", dn);
ResultPropertyValueCollection prop = result.Properties["whenChanged"];
if (prop != null)
{
Console.WriteLine(" {0}", (DateTime)prop[0]);
}
}
}