-
May 23rd, 2009, 03:08 PM
#1
Getting ActiveDirectory Listing
Hi, I have a piece of code (below) which grabs a list of users on an Active Directory. However it only seems to return the first 1500 users. Does anybody know how to modify this code so it returns all the users?
public ArrayList GetActiveADUsersInGroup()
{
ArrayList adUsersInGroup = new ArrayList();
String queryString = "LDAP://CN=ALL Employees,OU=Distribution Lists,OU=Exchange Objects,OU=System Management,DC=xxx,DC=corp,DC=local";
DirectoryEntry de = new DirectoryEntry(queryString);
PropertyValueCollection members = (PropertyValueCollection)de.Properties["member"];
foreach (object member in members)
{
String queryStringMember = "LDAP://" + member.ToString();
DirectoryEntry deMember = new DirectoryEntry(queryStringMember);
String windowsIdentityName = deMember.Properties["sAMAccountName"].Value.ToString();
adUsersInGroup.Add(windowsIdentityName);
}
return adUsersInGroup;
}
Thanks in advance
Srinu
-
May 23rd, 2009, 04:14 PM
#2
Re: Getting ActiveDirectory Listing
Hi,
Basically the problem is: The System.DirectoryServices namespace contains a flaw that may cause the group membership list to become truncated if new members are added to a group that already contains more than 1000 or 1500 members. Depending on system. On a computer that is running Microsoft Windows Server 2003, the group membership becomes truncated to 1500 members plus the newly added members. See FIX: The group membership list becomes truncated when you add group memberships by using the .NET Framework System.DirectoryServices namespace
You can use the Range retrieval to get all users, see code example in MSDN: Enumerating Members in a Large Group
Last edited by Loldemar; May 23rd, 2009 at 04:20 PM.
Reason: added more info for problem description
-
May 24th, 2009, 02:49 PM
#3
Re: Getting ActiveDirectory Listing
Hi Loldemar,
Thank you so much for your quick reply...i tried your soluation i mean using the range retrieval...but unfortunetly i dint get soluation with this for what i was looking for...i am desparte to get the soluation...Thank you once again for your response...i need to struggle to get the result if you had any other option please please kindly let me know
Thanks
-
May 24th, 2009, 03:22 PM
#4
Re: Getting ActiveDirectory Listing
They give you the code:
Code:
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://CN=My Distribution List,OU=Distribution Lists,DC=Fabrikam,DC=com");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectClass=*)";
uint rangeStep = 1000;
uint rangeLow = 0;
uint rangeHigh = rangeLow + (rangeStep - 1);
bool lastQuery = false;
bool quitLoop = false;
do
{
string attributeWithRange;
if(!lastQuery)
{
attributeWithRange = String.Format("member;range={0}-{1}", rangeLow, rangeHigh);
}
else
{
attributeWithRange = String.Format("member;range={0}-*", rangeLow);
}
searcher.PropertiesToLoad.Clear();
searcher.PropertiesToLoad.Add(attributeWithRange);
SearchResult results = searcher.FindOne();
searcher.Dispose();
foreach(string res in results.Properties.PropertyNames)
{
System.Diagnostics.Debug.WriteLine(res.ToString());
}
if(results.Properties.Contains(attributeWithRange))
{
foreach(object obj in results.Properties[attributeWithRange])
{
Console.WriteLine(obj.GetType());
if(obj.GetType().Equals(typeof(System.String)))
{
}
else if (obj.GetType().Equals(typeof(System.Int32)))
{
}
Console.WriteLine(obj.ToString());
}
if(lastQuery)
{
quitLoop = true;
}
}
else
{
lastQuery = true;
}
if(!lastQuery)
{
rangeLow = rangeHigh + 1;
rangeHigh = rangeLow + (rangeStep - 1);
}
}
while(!quitLoop);
}
catch(Exception ex)
{
// Handle exception ex.
}
-
May 25th, 2009, 01:37 AM
#5
Re: Getting ActiveDirectory Listing
Hi dglienna,
Thanks for reply....this soluation at last worked out for me....spl thanks Loldemar too.
Regards
srinu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|