locked
get samAccountName from group members using directory services RRS feed

  • Question

  • How do I get the SamAccountName  for all members of a group? Do I need to enum thru the "member" attribute  and use the DN to bind to each member object? This seems like a lot of work.

    Thanks 

    Friday, June 3, 2011 6:36 PM

Answers

  • Hello again,

    From your description, I suspect you want to filter the specific member information to bind. I think you can add If segment in the foreach one. If it caught the specific member, you can break this loop right now.

    Hope this helps.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by SBohringer Tuesday, June 7, 2011 2:56 PM
    Tuesday, June 7, 2011 5:38 AM
  • try

     {

    // Bind to the container to enumerate.

    DirectoryEntry ent = new DirectoryEntry(LDAP://CN=users,OU=Marketing,DC=fabrikam,DC=com);

    // Create an object to use for individual objects in the container and iterate

     // through the container.

    foreach( DirectoryEntry child in ent.Children)

     {

     // Write the name and path for each object in the container.

     Console.WriteLine(child.Properties[samAccountName].ToString());

    }

    }

    catch

    {

    // Handle errors.

    }

    Regards,

    Narendran Ponpandiyan

    • Marked as answer by SBohringer Tuesday, June 7, 2011 3:42 PM
    Tuesday, June 7, 2011 10:18 AM

All replies

  • Hi SBohringer,

    Thank you for posting.

    Regarding SamAccountName, you can check the following link about Active Directory Roles Provider. http://www.codeproject.com/KB/aspnet/active_directory_roles.aspx?msg=3156633

    Hope this helps. If I misunderstood, please feel free to elaborate your question kindly.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 6, 2011 5:54 AM
  • Larcolais Gong

    Thank You for your response. Let me elaborate my question. I have binded to a group. I am listing all members of the group using the members property

     foreach (object dn in group.Properties["member"])

    This gives me the dn of each member. What I need is the SamAccountName. Can I get this without binding to each member in the foreach loop?

    Thanks

    Monday, June 6, 2011 6:53 PM
  • Hello again,

    From your description, I suspect you want to filter the specific member information to bind. I think you can add If segment in the foreach one. If it caught the specific member, you can break this loop right now.

    Hope this helps.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by SBohringer Tuesday, June 7, 2011 2:56 PM
    Tuesday, June 7, 2011 5:38 AM
  • try

     {

    // Bind to the container to enumerate.

    DirectoryEntry ent = new DirectoryEntry(LDAP://CN=users,OU=Marketing,DC=fabrikam,DC=com);

    // Create an object to use for individual objects in the container and iterate

     // through the container.

    foreach( DirectoryEntry child in ent.Children)

     {

     // Write the name and path for each object in the container.

     Console.WriteLine(child.Properties[samAccountName].ToString());

    }

    }

    catch

    {

    // Handle errors.

    }

    Regards,

    Narendran Ponpandiyan

    • Marked as answer by SBohringer Tuesday, June 7, 2011 3:42 PM
    Tuesday, June 7, 2011 10:18 AM