简体   繁体   中英

searching users in active directory c# ldap

I am trying to get users who are members of a particular group in AD.

I am trying with the following filters but i am unsuccessful.

1)

DirectoryEntry entry1 = new DirectoryEntry("LDAP://DC=xxinfo,DC=com");
string query = "(&(objectCategory=person)(objectClass=user)(memberOf=CN=Guests))";

2)

objSearchADAM.Filter = "(&(ObjectClass=user)(memberOf=CN=Network Configuration perators,CN=Builtin,DC=xxxx,DC=xxinfo,DC=com))";

also, is there any way to get users using this approach?

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "group_name");

this searches the current domain, i want to search the whole forest.is there any way to initialize ctx for whole forest?

any help would be appreciated. thank you.

Got the answer!! used below code using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "subdomain.domain.comany.com:3268", "DC=comapny,DC=com")) { GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "Group_Name");

port 3268 is used to search in global catalog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM