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

  • Home
  • SEARCH
  • 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 8483767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:11:47+00:00 2026-06-10T20:11:47+00:00

To get all groups in Active Directory i have write this code in C#.

  • 0

To get all groups in Active Directory i have write this code in C#. It works perfectly well as i dont need to pass any servername, OU, DC etc.

        UserPrincipal current_user = UserPrincipal.Current;

        PrincipalContext current_context = current_user.Context;

        PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

        GroupPrincipal qbeUser = new GroupPrincipal(ctx);

        Principal userOrGroup = qbeUser as Principal;
        userOrGroup.Name = "*";

        PrincipalSearcher searcher = new PrincipalSearcher(userOrGroup);

        List<string> AllGroups = new List<string>();

        // 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)
            {
                AllGroups.Add(found.Name);

                //GroupPrincipal gp = found as GroupPrincipal;

                //var data = gp.GetMembers();

                // if it's a group - do whatever you need to do with a group....
            }
        }

        //return AllGroups;

The problem is that it list too many groups that i dont need like

PerformanceLogUsers, SchemaAdmins, HelpServiceGroups, Telnet Clients and so on.

I only need groups like Administrator, Guests and other user created group. I have read about something like these are special group and etc etc.

Any help in this regard is highly appreciated.

  • 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-06-10T20:11:49+00:00Added an answer on June 10, 2026 at 8:11 pm

    AD doesn’t discriminate by group relevance when performing searches. It’s either a group or it isn’t. However, you can specify whether or not to return security groups or distribution groups, for instance.

    How your directory is currently set up, is another matter. If the groups you want and the groups you don’t want are both “Security Groups”, then it’ll pose a problem.

    One solution to that would be finding some unique attribute that your relevant groups have in common (or create one) and then filter on the existence of those.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to connect to Active Directory and get all the groups
Active Directory. How can I get all security groups in a specific folder? Say
I am trying to get all of the CN's out of active directory in
I have some code that retreive the users present in different groups in Active
I want to list all the Active Directory application groups a user belongs to.
I am using this query to get all the data but I also need
In my Active Directory (my.domain), I have many groups (UserGrp1, UserGrp2, etc.) which have
As the title mentions I need a way to get all groups a group
To get all contacts I'm using ABAddressBookCopyArrayOfAllPeople method but, this method return all contacts
I'm pulling my hair out over this one. I want to get all contents

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.