我需要在C#应用程序中从Active Directory中读取msDS-ReplAttributeMetaData属性。当我以自己的身份运行代码时,使用普通的DirectorySearcher可以看到比以不同用户身份运行时多得多的属性。我的AD管理员告诉我,帐户之间应该没有区别。
有人知道我可以让他们查看的特定权限吗?我尝试读取的特定项是pszAttributeName为unicodePwd的位置,这样我就可以获得最后的更改日期。
我知道PwdLastSet属性,但是当帐户设置为永不过期时,密码将经常具有值0,因此我必须进入元数据。
这是我用来运行查询的代码。
var searcher = new DirectorySearcher {
SearchRoot = new DirectoryEntry("GC://DC=..."),
SearchScope = SearchScope.Subtree,
Filter = "(&(objectCategory=User)(SamAccountName=...))",
PageSize = 1000
};
var numFound = 0;
try {
searcher.PropertiesToLoad.Clear();
searcher.PropertiesToLoad.Add("msDS-ReplAttributeMetaData");
var result = searcher.FindOne();
foreach (string xml in result.Properties["msDS-ReplAttributeMetaData"]) {
numFound++;
var doc = XDocument.Parse(xml);
var element = doc.XPathSelectElement("//ftimeLastOriginatingChange[../pszAttributeName='unicodePwd']");
if (element == null)
continue;
Console.WriteLine(element.Value);
}
} finally {
searcher.Dispose();
}
Console.WriteLine($"Done - I found {numFound}");在我的账户上写着找到40,在另一个账户上写的是33。
发布于 2019-08-09 02:03:41
尝试使用LDAP://而不是GC://。GC可能会给出不同的结果,因为并非所有属性都会复制到全局编录中。msDS-ReplAttributeMetaData属性在您请求它的时候被构造,因此它取决于您请求构造它的服务器。因此,它可能只报告实际复制到该服务器的属性。
如果您最终访问的是不同域上的服务器(如果您的环境中有多个域),这一点尤其正确。
https://stackoverflow.com/questions/57418226
复制相似问题