Output members of AD group and nested groups with path inside script task

  • Thread starter Thread starter msdnpublic1234
  • Start date Start date
M

msdnpublic1234

Guest
Hi,

I was able to get members of group and nested groups ,i would also like to output the group within which the user falls.

Example, Nancy belongs to the Security group Oracle that I am looking into,but she is part of this group indirectly,meaning belonging to another group called Analytics.This group Analytics has been added to Oracle group.Hence,she is part of Oracle through Analytics.

Basically,i want output the nested group name (if applicable to a user besides their names: if a user is directly added to Oracle,they appear as just Oracle,else nestedgroup\Oracle) .Any other format besides one I mention below for ADGroup that conveys what is the group the user is coming from will suffice.

I tried the below to get the list of all users within AD group ,but not sure of how to get nested groups names alongwith.

public void Main()

{

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "abc.com");
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Oracle");

if (grp != null)
{
foreach (Principal p in grp.GetMembers(true))
{

System.IO.File.AppendAllText(@"C:\Users\JDoe\Documents\Test.txt", "Date :" + DateTime.Now.ToString() + "\t" + "Message :" + p.Name +Environment.NewLine);
}

grp.Dispose();
ctx.Dispose();

}
else
{
System.IO.File.AppendAllText(@"C:\Users\Jdoe\Documents\Test.txt", "Date :" + DateTime.Now.ToString() + "\t" + "Message :We did not find that group:" + grp + " in that domain, perhaps the group resides in a different domain" + Environment.NewLine);
}

}

1360181.png

Continue reading...
 
Back
Top