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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:07:35+00:00 2026-06-06T05:07:35+00:00

I am new to stackoverflow as a member, although I follow this a lot

  • 0

I am new to stackoverflow as a member, although I follow this a lot 🙂
My code which connects to active directory to get the members of a functional group, gives me only 1490 odd members out of 1680 odd members actually in the list. I have searched a lot on Stackoverflow and on Internet, but I have not found out answer to why the code would result in incomplete list. Could, anyone please give me any pointers on this. Thanks 🙂

Here is the code which connects to the Active Directory to retrieve the data:

    public static DataTable GetAdUsers(string configSection)
    {

        DataRow dr; 
        Hashtable ADGroups = (Hashtable)ConfigurationManager.GetSection(configSection);
        string adGroup;
        string adGroupDesc;
        string sApplication;
        string sLast_Login;
        string sAccount_owner;
        string sPath;

        DataTable dt = new DataTable();

        sApplication = "Application";
        dt.Columns.Add(sApplication);

        dt.Columns.Add("Profile", Type.GetType("System.String"));
        dt.Columns.Add("Account Name", Type.GetType("System.String"));

        sLast_Login = "Last Login";
        dt.Columns.Add(sLast_Login);

        sAccount_owner = "Account Owner";
        dt.Columns.Add(sAccount_owner);

        sPath = "Path";
        dt.Columns.Add(sPath);

        string domainName = "myDomain";

        PrincipalContext pcRoot = new PrincipalContext(ContextType.Domain, domainName);
        IDictionaryEnumerator adGroupEnumerator = ADGroups.GetEnumerator();

        while (adGroupEnumerator.MoveNext())
        {
            adGroup = adGroupEnumerator.Key.ToString();
            adGroupDesc = adGroupEnumerator.Value.ToString();

            GroupPrincipal grp = GroupPrincipal.FindByIdentity(pcRoot, IdentityType.SamAccountName, adGroup); 
            System.DirectoryServices.DirectoryEntry de = (System.DirectoryServices.DirectoryEntry)grp.GetUnderlyingObject();
            foreach (string sDN in de.Properties["member"])
            {
                System.DirectoryServices.DirectoryEntry deMember = new System.DirectoryServices.DirectoryEntry("LDAP://" + sDN.ToString());
                try
                {
                    dr = dt.NewRow();

                    string output1;
                    string subStringE1 = "DC=";
                    int length1 = de.Path.ToString().Length;
                    int length0 = de.Path.ToString().IndexOf(subStringE1);
                    string str1 = de.Path.ToString().Substring(length0, length1 - length0);
                    string subStringE2 = ",DC";
                    int length2 = str1.ToString().IndexOf(subStringE2);
                    output1 = str1.ToString().Substring(3, length2 - 3);

                    dr["Application"] = "Application";
                    dr["Profile"] = adGroupDesc;

                    string AccountName = deMember.Properties["samAccountName"].Value.ToString();

                    dr["Account Name"] = deMember.Properties["samAccountName"].Value.ToString();
                    dr["Last Login"] = "";
                    dr["Account Owner"] = deMember.Properties["givenName"].Value.ToString() + @"-" + deMember.Properties["sn"].Value.ToString();

                    string Path = output1 + @"\" + adGroup + @"\" + deMember.Properties["samAccountName"].Value.ToString();

                    Console.WriteLine(Path);
                    dr["Path"] = output1 + @"\" + adGroup + @"\" + deMember.Properties["samAccountName"].Value.ToString();

                    dt.Rows.Add(dr);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error occured for user name" + sDN + "\n" + ex.Message);
                }
            }
        }
        return dt;
    }
}
  • 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-06T05:07:38+00:00Added an answer on June 6, 2026 at 5:07 am

    Because of the default limit of SizeLimit, you’re probably only getting around the 1,490 objects or so. To fix that you need to “page” through the results.

    Just use the code referenced at Enumerating Members in a Large Group .

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

Sidebar

Related Questions

I like to thank stackoverflow member AlbertEin for helping with this code. What I
I'm using a bit of code suggested by a member on stackoverflow and adapted
Stackoverflow members, How do you currently find the balance between javascript and code behind.
I have the following JQuery code which does similar functionality like Stackoverflow where the
I have read a few threads on StackOverflow about this, but cannot get it
Today, a fellow team member checked-in some code that looked like this var query
I have seen some code for working with AD in this stackoverflow question I
I am new to StackOverFlow and wish there are experts to my problem, which
Hello fellow stackoverflow members! I'm very new to the C# language transfer from Java,
I'm playing a little bit with the new StackOverflow API . Unfortunately, my JSON

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.