문제
글로벌 카탈로그에 대해 쿼리 (sds.p를 사용하려고 할 계획)를 수행하면 전체 GC를 검색 할 수 있도록 시작 경로는 무엇입니까?
예를 들어 GC의 모든 사용자를 열거하고 싶습니다. 내 GC에 3 개의 도메인 (부모, 2 명의 자녀)에 대한 사용자가 있다고 가정 해 보겠습니다.
TEST.COM
ONE.TEST.COM
TWO.TEST.COM
그리고 나는 하나의 컴퓨터에 있습니다 .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( );
}
}
제휴하지 않습니다 StackOverflow