User Information from Active Directory

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
In the following code; it returns users name. How do I get the users manager name and the group user belongs to?

<pre class="prettyprint string groupName = "Domain Users";
string domainName = "MyDomain.com";
listBox1.Items.Clear();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName);
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName);
if (grp != null)
{
foreach (Principal p in grp.GetMembers(false))
{
Console.WriteLine(p.SamAccountName + " - " + p.DisplayName);
}


grp.Dispose();
ctx.Dispose();
Console.ReadLine();
}
else
{
Console.WriteLine("nWe did not find that group in that domain, perhaps the group resides in a different domain?");
Console.ReadLine();
} [/code]
<br/>

View the full article
 
Back
Top