简体   繁体   中英

How to filter out built in user(Guest) and group(Admin) in Active Directory using C#?

I am writing code to get users & groups from Active Directory, but I want to filter out built-in users & groups. built-in users eg: Guest Here is code snippet

subOUsearcher.SearchScope = SearchScope.Subtree;

subOUsearcher.Filter = "(&(objectClass=user)(objectCategory=person))";

var objSearchResults = subOUsearcher.FindAll();

Really, you just need to look for an attribute that is specific to built-in accounts. I took a look myself (using the "Attribute Editor" tab in AD Users and Computers), and I found the isCriticalSystemObject attribute, which you can use in your filter like this:

subOUsearcher.Filter = "(&(objectClass=user)(objectCategory=person)(!isCriticalSystemObject=TRUE))";

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