Hi, I am looking a way to retrieve the entire employee information from active directory. these are the codes I used. But I can not find all data, I only get employee name or login id.
The other data such Employee Number, Email address, Superviser name, Phone Number, etc can not be retrieved. I may use the wrong object.
Can anybody show me what is the correct object for retrieving all employee information?
To load all the attributes, you should not configure the field PropertiesToLoad. In your above case, searcher will load only name, samaccountname and userprincipalname attributes only.
To load all the attributes, you should not configure the field PropertiesToLoad. In your above case, searcher will load only name, samaccountname and userprincipalname attributes only.
Hi ASNALbert, thanks a lot for your help, could you please post any examples, so I can follow. thanks
Member
366 Points
2214 Posts
How to retrieve the entire employee information from Active Directory?
Oct 22, 2013 06:30 PM|Peter Cong|LINK
Hi, I am looking a way to retrieve the entire employee information from active directory. these are the codes I used. But I can not find all data, I only get employee name or login id.
The other data such Employee Number, Email address, Superviser name, Phone Number, etc can not be retrieved. I may use the wrong object.
Can anybody show me what is the correct object for retrieving all employee information?
var searcher = new DirectorySearcher();
searcher.PropertiesToLoad.Add("name");
searcher.PropertiesToLoad.Add("samaccountname");
searcher.PropertiesToLoad.Add("userprincipalname");
searcher.Filter = String.Format("(&(objectClass=user)(samaccountname={0}))", loginId);
var results = searcher.FindAll();
return results.Cast<SearchResult>()
.Where(s => s.Properties.Contains("userprincipalname"))
.Select(TranslateSearchResultToADUser).Single();
TT
Member
30 Points
15 Posts
Re: How to retrieve the entire employee information from Active Directory?
Oct 23, 2013 12:38 AM|ASNAlbert|LINK
To load all the attributes, you should not configure the field PropertiesToLoad. In your above case, searcher will load only name, samaccountname and userprincipalname attributes only.
TT
AdSysNet Solutions
Member
366 Points
2214 Posts
Re: How to retrieve the entire employee information from Active Directory?
Oct 23, 2013 07:40 AM|Peter Cong|LINK
Hi ASNALbert, thanks a lot for your help, could you please post any examples, so I can follow. thanks
TT
All-Star
23975 Points
4084 Posts
Re: How to retrieve the entire employee information from Active Directory?
Oct 24, 2013 01:37 AM|Starain chen - MSFT|LINK
Hi Peter,
Thanks for your post!
I think you should add the properities that you want into DirectorySearcher, like this code:
There is a simple sample (I searched) that may help you:
Thanks
Best Regards
TT