Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

Good Morning,

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 :
C#
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain);
GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, "IT_DEPARTMENT_USERS");
foreach (var userPrincipal in GroupPrincipal.FindByIdentity(principalContext, "IT_DEPARTMENT_USERS").GetMembers().OfType<UserPrincipal>())
{
    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..?
Posted
Updated 8-May-16 22:22pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900