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 6476897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:52:55+00:00 2026-05-25T06:52:55+00:00

I’m trying to get all users that belong to a group in the Active

  • 0

I’m trying to get all users that belong to a group in the Active Directory. I want to display the result as a drop down for the site users to select. This is what I have so far:

public IEnumerable<KeyValuePair<string, string>> GetAllMembers(string group)
{
    var domainContext = new PrincipalContext(ContextType.Domain);
    var group = GroupPrincipal.FindByIdentity(domainContext, group);

    return from principal in @group.Members select new KeyValuePair<string, string>(/* need to fill in key and value */);
}

The problem I have is that I am developing this outside of an active directory so cannot really test it yet (long story don’t ask). I want to maximise my chances of success when deploying this into a testing environment.

My question is: if I want the key value pair to contain login username (key, ex: "DOMAIN\darkoz") and the users real name (value, ex: "Darko Z"), how do I get those? the Principal object has at least 5 properties with the word Name in it so I’m not sure which is which.

Bonus question: is this a generally accepted way of achieving my goal? I realize it is a very simple problem but with my lack of knowledge of Active Directory, I wouldn’t be surprised if there was a better way of doing this. Will this work running on an account that is not admin?

  • 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-25T06:52:56+00:00Added an answer on May 25, 2026 at 6:52 am

    The solution was as I suspected:

    public IEnumerable<KeyValuePair<string, string>> GetAllMembers(string group)
    {
        var domainContext = new PrincipalContext(ContextType.Domain);
        var groupPrincipal = GroupPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, group);
    
        return from m
               in groupPrincipal.Members 
               select new KeyValuePair<string, string>(m.SamAccountName, m.Name);
    }
    

    where the SamAccountName gives the users logon name and the Name is the actual name

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.