我想从ActiveDirectory
读取Parent-GUID
属性。
我已经尝试了下面的代码来从活动目录中读取AD对象的所有属性。
法典
var dirEntry = new DirectoryEntry(directoryEntryPath);
var directorySearcher = new DirectorySearcher(dirEntry, filter)
{
CacheResults = false,
Tombstone = true,
};
var searchResult = directorySearcher.FindAll(); // get mutiple AD Objects
foreach (SearchResult search in searchResult)
{
foreach (DictionaryEntry prop in search.Properties) // here I get all attributes values But not able to find parent-GUID attribute
{
}
}
使用上面的代码,我能够获取AD对象的所有属性,但无法获取父GUID属性的值。
根据https://learn.microsoft.com/en-us/windows/desktop/adschema/a-parentguid 这是一个构造属性。这意味着它不会包含在搜索结果中。文档还暗示它在那里支持目录同步,这告诉我它可能在目录同步搜索之外不可用。
你的意思是这样吗?
string path = "CN=someone,OU=yourOrganizationalUnit,DC=example,DC=com";
DirectoryEntry root = new DirectoryEntry(path);
root.Parent.Guid.ToString(); // this will display you the GUID from the parent of your path
希望这就是你的意思!
干杯,
ov4rlrd
var searchResult = directorySearcher.FindAll();
foreach(SearchResult search in searchResult)
{
DirectoryEntry de = search.GetDirectoryEntry();
Guid ParentGUID = new Guid((byte[])de.Parent.Properties["objectGUID"][0]);
...
}