Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:35:41+00:00 2026-05-28T20:35:41+00:00

It seems System.DirectoryServices.AccountManagement provides query by example which can only search one type of

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:35:42+00:00Added an answer on May 28, 2026 at 8:35 pm

    I believe you should be able to do this in S.DS.AM. Both the UserPrincipal as well as the GroupPrincipal ultimately descend from Principal – 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 Principal is an abstract class, so you cannot directly instantiate it – you need to get a UserPrincipal first and “extract” the generic Principal from that:

    // set up dummy UserPrincipal
    UserPrincipal qbeUser = new UserPrincipal(ctx);
    
    // get the generic Principal from that - set the "Name" to search for
    Principal userOrGroup = qbeUser as Principal;
    userOrGroup.Name = "SomeName";
    
    // create a PrincipalSearcher based on that generic principal
    PrincipalSearcher searcher = new PrincipalSearcher(userOrGroup);
    
    // enumerate the results - you need to check what kind of principal you get back
    foreach (Principal found in searcher.FindAll())
    {
        // is it a UserPrincipal - do what you need to do with that...
        if (found is UserPrincipal)
        {
            ......
        }
        else if (found is GroupPrincipal)
        {
            // if it's a group - do whatever you need to do with a group....
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that I can't control the NSApp delegate from within a System Preferences
It seems to not get past this step: [ 16%] Building CXX object src/CMakeFiles/hphp_runtime_static.dir/lib/system/gen/sys/dynamic_table_func.no.cpp.o
I know I can use System.DirectoryServices to roll my own GAL Name/email selector control
It seems the System.Management.Automation assembly only ever exists in version 1.0.0.0 on my system,
I'm using the System.DirectoryServices.AccountManagement namespace classes to manage the membership of several groups. These
I'm working on an admin page in PHP in which a user system seems
I have the following: using System; using System.DirectoryServices.AccountManagement; public class ChangePassword { public static
Dim de As New System.DirectoryServices.DirectoryEntry() Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
stackoverflow! We are developing system, which should be horizontal scalable. So, messaging system seems
I'm using System.DirectoryServices.AccountManagement namespace classes to add and manage users in AD, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.