gpt4 book ai didi

c# - GetDirectoryEntry 不返回所有属性

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:33 26 4
gpt4 key购买 nike

我正在尝试查询 AD 以检索用户数据。

查询工作正常,但是在枚举通过 GetDirectoryEntry 返回的属性时我无法看到我在 Active Directory 资源管理器中看到的所有属性。

下面的代码片段:

offEntry = pResult.GetDirectoryEntry();
foreach (PropertyValueCollection o in offEntry.Properties)
{
Debug.Print(o.PropertyName + " = " + o.Value.ToString());
}

我看到了“displayName”和“SAMAccountName”等属性,但不是我真正想要的属性,例如:“postalCode”、“streetAddress”。

我曾尝试为这个特定问题寻找解决方案,但已走到尽头。我错过了什么???

问候彼得

最佳答案

您应该能够使用这样的搜索器类。

DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(sAMAccountName=" + userAccount + ")";
search.PropertiesToLoad.Add("mail");
SearchResult result = search.FindOne();

然后通过行加载你想要的属性

            search.PropertiesToLoad.Add("mail");

然后在您的 SearchResult 中您将能够读取属性

关于c# - GetDirectoryEntry 不返回所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11363446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com