【发布时间】:2014-10-27 23:22:47
【问题描述】:
我正在尝试获取活动目录“标准”组中的所有计算机名称。 AD 树如下所示:
我尝试使用“memberOf”属性获取计算机(我在此页面上找到了属性:http://www.kouti.com/tables/userattributes.htm)。所以我有这个代码:
using (var context = new PrincipalContext(ContextType.Domain, "bbad.lan"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry entry = result.GetUnderlyingObject() as DirectoryEntry;
if (entry.Properties["memberOf"].Value == "Computer")
{
MessageBox.Show("aaa: " + entry.Properties["Name"].Value.ToString());
}
}
}
}
调试此代码后,因为它没有显示任何消息框,我发现“memberOf”属性返回一些奇怪的字符串。我使用MessageBox.Show(entry.Properties["memberOf"].Value.ToString()); 来获取“memberOf”属性的值。这是我得到的:
1. MsgBox: CN=Gäste,CN=Builtin,DC=bbad,DC=lan
2. MsgBox: System.Object[]
etc.
还有更多的 MsgBoxes,但每个盒子都是这样的。
查看我们的活动目录后,我无法确定条目显示的顺序。而且我注意到没有像“计算机”(见图)这样的东西出现。
结论:我只是想把电脑放在bbad.lan > Computer > Standard,但是我的代码结果让我很困惑,所以我现在很困惑。
建议赞赏:)
【问题讨论】:
标签: c# active-directory