0

I want to get number of users/groups in a domain without loading all the users/groups.

Is this possible? especially in c#?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
gimbup
  • 184
  • 3
  • 18
  • This could probably help you for that : [Get Count of members in a AD Group using PrincipalSearcher](http://stackoverflow.com/questions/35089911/get-count-of-members-in-a-ad-group-using-principalsearcher) – Marc Roussel Aug 18 '16 at 13:57
  • This link above still loads all users before getting the count. – gimbup Aug 18 '16 at 14:28
  • There's no way around internally or externally to count without enumerating a collection. The concept of counting is to enumerate a collection. For instance if I have a collection of students even doing Students.Count will go through all of them internally one way or other. Another example is a C# DataSet RowCount. Just asking it will take a certain amount of time if you have a lot of records. Guess why ? – Marc Roussel Aug 19 '16 at 11:59
  • On another note, I saw people keeping RowCount and adding one when a student is added thus always having the count but this also imply that if you delete a student you have to decrease your RowCount – Marc Roussel Aug 19 '16 at 12:01

1 Answers1

0

This is not really possible in AD. You need to query LDAP with an appropriate filter and count the results. There is a numSubordinates attribute that exists in some LDAP implementations which will tell you how many objects exist underneath a specific object, but AD does not support it. The closest you can get is msDS-Approx-Immed-Subordinates.

However, even if one of the above attributes were available, there's no way to make a distinction between the type of subordinate objects in the count. Unless you can guarantee that only users/groups reside under a specific structure in your directory and nothing else.

ChadSikorra
  • 2,829
  • 2
  • 21
  • 27