代码之家  ›  专栏  ›  技术社区  ›  Kasper

如何访问GroupPrincipal对象上的notes字段

  •  1
  • Kasper  · 技术社区  · 17 年前

    PrincipalSearchResult<Principal> results = ps.FindAll();
    

    其中ps是一个主要的研究者。

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

    但是AD中的Notes字段显然不是GroupPrincipal类doh中的公共字段。

    更新: 我已经放弃了这一点。似乎没有办法进入那个讨厌的Notes字段。

    4 回复  |  直到 17 年前
        1
  •  7
  •   Brad    16 年前

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

    // 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来拯救它!

        2
  •  1
  •   Kasper    17 年前

    我一次又一次地回到这个挑战,但现在我终于放弃了。看起来这个属性确实不可访问。

        3
  •  1
  •   Daniel    14 年前

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

        4
  •  1
  •   user2729442    12 年前

    我能够改变这个领域。

    entryToUpdate.Properties[“info”].Add(“此处需要的一些文本”);

    所以,谢谢布拉德:)