如果我对全局目录进行查询(我计划使用 SDS.P),那么起始路径应该是什么,以便我可以搜索整个 GC?
例如,我想枚举 GC 中的所有用户。假设我的 gc 有 3 个域的用户(一个父母,两个孩子):
TEST.COM
ONE.TEST.COM
TWO.TEST.COM
我在 ONE.TEST.COM 的电脑上。我不想硬编码 DC=XXX,DC=yyy,我想在运行时确定。
蒂亚!-将要
这是一个查询全局目录的示例函数:
class Program
{
static void Main()
{
DirectoryEntry entry = new DirectoryEntry("GC://dcserver.domain.local",
"utility",
"somepassword",
AuthenticationTypes.Secure );
const string searchString = "(&(objectCategory=person)(objectClass=user))";
DirectorySearcher searcher = new DirectorySearcher(entry,
searchString,
new string[] { "sAMAccountName", "cn" } );
SearchResultCollection resultCollection = searcher.FindAll( );
foreach ( SearchResult result in resultCollection )
{
Console.WriteLine( result.Path + "\n" +
result.Properties["cn"][0] + "\n" +
result.Properties["samaccountname"][0] );
}
Console.ReadLine( );
}
}