2008-11-27 29 views
1

我查询所有安全组在特定领域上的备注字段。如何访问使用</p> <pre><code>PrincipalSearchResult<Principal> results = ps.FindAll(); </code></pre> <p>其中Ps是PrincipalSearcher一个GroupPrincipal对象

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

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

更新: 我放弃了这一个。似乎没有办法访问那个讨厌的Notes字段。

回答

1

我已经一次又一次地回到这个挑战,但现在我终于放弃了。它确实看起来像该属性是无法访问。

6

,您可以访问“注释”目录项的字段,例如:

// 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属性确实被称为“笔记”,ADSIEDIT救援!

+0

这应该是公认的答案=) – 2013-07-08 20:25:06

1

对于使用“info”属性的任何人:请注意,如果使用空字符串或空值,它将引发异常。

1

我能够改变这个领域。

entryToUpdate.Properties [“info”]。Clear(); entryToUpdate.Properties [“info”]。Add(“你想要的某些文本在这里”);

所以感谢布拉德:)

+0

请尝试读取这个http://stackoverflow.com/about,以获取有关在这里做题/答案更多的了解。你的贡献没有回答这个问题。这更多的是一个评论,你可以添加一次,你会增加你的声誉:http://stackoverflow.com/faq#reputation – 2013-08-29 13:44:07

相关问题