Blue sky, wind, cloud and knulf

AD에서 목록 조회 본문

라이브러리/개발

AD에서 목록 조회

눌프 2012. 4. 12. 19:43

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.DirectoryServices;

using System.DirectoryServices.AccountManagement;


namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{


// Login to AD

string strLdapPath = "LDAP://192.168.10.10/DC=kitg,DC=local";

DirectoryEntry objDE = new DirectoryEntry(strLdapPath, "xenadmin", "xenxptmxm");


try

{

DirectorySearcher searcher = new DirectorySearcher(objDE);

//searcher.Filter = "(&(objectCategory=person)(objectClass=user))";

searcher.Filter = "(objectCategory=organizationalUnit)";

SearchResultCollection srs = searcher.FindAll();


foreach (SearchResult sr in srs)

{

if (sr != null)

{

DirectoryEntry objUser = sr.GetDirectoryEntry();

Console.WriteLine("======================================================================");

//Console.WriteLine("distinguishedName: " + objUser.Properties["distinguishedName"].Value.ToString());

foreach (string key in objUser.Properties.PropertyNames)

{

Console.WriteLine(key + ": " + objUser.Properties[key].Value.ToString());

}

Console.WriteLine("\n");

}

}

}

catch (Exception ex)

{

Console.WriteLine(ex.ToString());

}


}

}

}


Comments