C# - Filtering a DirectorySearcher for groupmember

2019-09-18 15:03发布

问题:

my issue is about filtering members of a specific group to be not shown in the userlist. So far to that, this is my code to filter them out so far:

searcher.Filter = string.Format("(&(cn=*{0}*)(objectCategory=person)(objectClass=user)(!(adminCount=1))(!(cn=*Admin*)))",SuchfeldNachName.Text).Replace("**","*");

This is how I am trying to filter it right now. Obviously, I am trying to not show admins in the userlist. But thats not a fine solution for me, because in the final state, I want it to filter out four specific Active Directory groups.

These are the four groups I want to filter out:

  • Domain Admins
  • Enterprise Admins
  • Policy Creator Owner
  • Schema Admins

Now my question:

Is there a possible way to filter out the groupID's? So that the users in these groups are not shown in my userlist.

My idea was something like

(!(primaryGroupID= 512)) 

Second part of my question: Is there a list for all the group ID's?

Appreciate help in advance!