954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to get list of users from AD Group?

Hi All,

I need desperate help.

I have a group "MyGroupABC" in Active Directory (AD). In this group there are close to 100 list of users.

How can i write a logic to actually to get me the list of users with their particulars details such as Name, SN, GivenName, Telephone, Mail, etc?

I've been trying many days to figuring it out, but not success.

Below is my simple code.

DirectorySearcher ds = new DirectorySearcher("");
ds.SearchRoot = new DirectoryEntry("LDAP://myserver/CN=MyGroupABC,OU=MyProject,OU=DEVApplications,DC=myserver,DC=local");
ds.PropertyNamesOnly = true;
ds.PropertiesToLoad.Add("name");
ds.PropertiesToLoad.Add("sn");
ds.PropertiesToLoad.Add("givenName");
ds.PropertiesToLoad.Add("mail");
ds.PropertiesToLoad.Add("telephoneNumber");

SearchResultCollection src = ds.FindAll();

try 
{
   foreach (SearchResult sr in src)
   {
      string str1 = de.name.ToString();
      string str2 = de.sn.ToString();
      string str3 = de.givenName.ToString();
      string str4 = de.mail.ToString();
      string str5 = de.telephoneNumber.ToString();
   }
}
catch (Exception e)
{
   MessageBox.Show(e.Message);
}

the ds.FindAll() result get returns empty.

Is there any better way to do around this?

vinothrao84
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Hi,

It could be a permissions error, naturally enough your AD is well protected - i'd never recommend querying it directly from a web page you're better building a comm object or something to do it for you and then just pulling back the data from that.

G_Waddell
Posting Whiz in Training
255 posts since Nov 2009
Reputation Points: 43
Solved Threads: 27
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: