It seems System.DirectoryServices.AccountManagement provides query by example which can only search one type of object at a time.
Does System.DirectoryServices.AccountManagement proves a method using which I can search entire active directory for users or groups matching a particular name or some other criteria or I have to go back to System.DirectoryServices.DirectorySearcher.
I believe you should be able to do this in S.DS.AM. Both the
UserPrincipalas well as theGroupPrincipalultimately descend fromPrincipal– so if you pass in a “generic” principal to the searcher, you should get back both users and groups (and computers).The only tricky part is that
Principalis an abstract class, so you cannot directly instantiate it – you need to get aUserPrincipalfirst and “extract” the genericPrincipalfrom that: