Thursday, February 7, 2008

Importing data from active directory

DirectoryEntry oRoot = new DirectoryEntry
("LDAP://OU=Development,OU=Engineering,dc=MOSS2007,dc=com");
//My domain name is called MOSS2007.com
//I have OU Engineering and below I have Development

DirectorySearcher oSearcher = new DirectorySearcher(oRoot);
SearchResultCollection oResults;
oResults = oSearcher.FindAll();

for (int i = 0; i < oResults.Count; i++)
{
if (oResults[i].GetDirectoryEntry().Properties["cn"].Value != null)
Response.Write(oResults[i].GetDirectoryEntry().Properties["cn"].Value + " , ");
}
------------------------------------------------------------------------------
Variables you can use:
[0]: "homemdb"
[1]: "countrycode"
[2]: "cn"
[3]: "msexchuseraccountcontrol"
[4]: "mailnickname"
[5]: "msexchhomeservername"
[6]: "msexchhidefromaddresslists"
[7]: "msexchalobjectversion"
[8]: "usncreated"
[9]: "objectguid"
[10]: "msexchrequireauthtosendto"
[11]: "whenchanged"
[12]: "memberof"
[13]: "accountexpires"
[14]: "displayname"
[15]: "primarygroupid"
[16]: "badpwdcount"
[17]: "objectclass"
[18]: "instancetype"
[19]: "msmqdigests"
[20]: "objectcategory"
[21]: "samaccounttype"
[22]: "whencreated"
[23]: "lastlogon"
[24]: "useraccountcontrol"
[25]: "msmqsigncertificates"
[26]: "samaccountname"
[27]: "userparameters"
[28]: "mail"
[29]: "msexchmailboxsecuritydescriptor"
[30]: "adspath"
[31]: "lockouttime"
[32]: "homemta"
[33]: "description"
[34]: "msexchmailboxguid"
[35]: "pwdlastset"
[36]: "logoncount"
[37]: "codepage"
[38]: "name"
[39]: "usnchanged"
[40]: "legacyexchangedn"
[41]: "proxyaddresses"
[42]: "userprincipalname"
[43]: "admincount"
[44]: "badpasswordtime"
[45]: "objectsid"
[46]: "msexchpoliciesincluded"
[47]: "mdbusedefaults"
[48]: "distinguishedname"
[49]: "showinaddressbook"
[50]: "givenname"
[51]: "textencodedoraddress"
[52]: "lastlogontimestamp"


HTH

1 comments:

Sam said...

very very nice article. i have tried it and achieved the targeted results :)