EDN Admin
Well-known member
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
<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