Last post May 10, 2016 07:49 AM by gani7787
May 05, 2016 08:35 AM|gani7787|LINK
How to get users countrycode and department from Particular AD Group using C#. I can retrieve other fields like, empid,firstname,lastname,etc,.
But, I need country code and department along with this results.
GROUP NAME : IT_DEPARTMENT_USERS --> 50 users available in this group.
see my below code :
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain); GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, "IT_DEPARTMENT_USERS"); foreach (var userPrincipal in GroupPrincipal.FindByIdentity(principalContext,
string EmpNo = userPrincipal.EmployeeId;
string DispName = userPrincipal.DisplayName;
string Email = userPrincipal.EmailAddress;
string firstName = userPrincipal.GivenName;
string lastName = userPrincipal.Surname;
string SamAccountName = userPrincipal.SamAccountName;
//string Dept = userPrincipal
there is no property like department and country in "userprincipal"
what is the solution for this..?
May 06, 2016 05:19 AM|gani7787|LINK
waiting for long time....
May 09, 2016 04:16 AM|gani7787|LINK
No solution for this in Microsoft...?
May 09, 2016 06:03 AM|Angie xu - MSFT|LINK
To get user details from active directory group c#, how about this code snippet?
using (var context = new PrincipalContext(ContextType.Domain, "domainName"))
using (var group = GroupPrincipal.FindByIdentity(context, "groupName"))
if (group == null)
MessageBox.Show("Group does not exist");
var users = group.GetMembers(true);
foreach (UserPrincipal user in users)
//user variable has the details about the user
Have a good day.
May 09, 2016 10:06 AM|gani7787|LINK
Thanks for your help.
Your answer is 50% correct.
But, I want to fetch Coutrycode,co(company) particulary. This will be available in LDAP attributes.
But,This will not be available in "UserPrincipal" properties.
How to fetch thses two fields in UserPrincipal...?
May 10, 2016 07:49 AM|gani7787|LINK