c# - 如何访问 GroupPrincipal 对象上的备注字段

标签 c# active-directory

我使用

查询特定域中的所有安全组
PrincipalSearchResult<Principal> results = ps.FindAll();

其中 ps 是 PrincipalSearcher。

然后我需要迭代结果(首先将其转换为 GroupPrincipal)并在注释字段中找到包含特定字符串的结果。

但是 AD 中的 Notes 字段显然不是 GroupPrincipal 类中的公共(public)字段,doh。 我做错了什么?

更新: 我已经放弃了这个。似乎无法访问那个讨厌的 Notes 字段。

最佳答案

您可以这样访问目录条目的“注释”字段:

// Get the underlying directory entry from the principal
System.DirectoryServices.DirectoryEntry UnderlyingDirectoryObject =
     PrincipalInstance.GetUnderlyingObject() as System.DirectoryServices.DirectoryEntry;

// Read the content of the 'notes' property (It's actually called info in the AD schema)
string NotesPropertyContent = UnderlyingDirectoryObject.Properties["info"].Value;

// Set the content of the 'notes' field (It's actually called info in the AD schema)
UnderlyingDirectoryObject.Properties["info"].Value = "Some Text"

// Commit changes to the directory entry
UserDirectoryEntry.CommitChanges();

进行了一些搜索 - 我假设 notes 属性确实被称为“notes”,ADSIEdit 来拯救!

关于c# - 如何访问 GroupPrincipal 对象上的备注字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/323817/

相关文章:

asp.net-mvc - 将 .NET MVC 应用程序中的 User.Identity 映射到事件目录用户

c# - WCF 的凭证委托(delegate)问题

c# - 使用 EF4 CTP5 中的 POCO 删除多对一关系中的子实体

c# - 不能同时使用 Bind 和 ConfigureConsumer

java - 查询 AD 以获得无限结果

c# - 有什么方法可以区分 "people user accounts"和 "computer user accounts"吗?

c# - 使用 Entity Framework 获取特定类型的实体返回错误 - LINQ to Entities 无法识别方法 'System.Type GetType()'

c# - .NET 在第 3 方应用程序中获取所有异常

php - 使用 PHP LDAP 更改(而不是重置)用户密码

azure - 如何获取Azure Active Directory Graph(不是Microsoft Graph)的服务主体?