List the users

  • Thread starter Thread starter Peter Tragardh
  • Start date Start date
P

Peter Tragardh

I want my program to create a list of every user in the domain that is part
of a special group. Any ideas?
 
Check out the DirectoryServices Namespace.
You'll need to include a reference to System.DirectoryServices.dll in your project first.
 
I want my program to create a list of every user in the domain that is part
of a special group. Any ideas?

Check out System.DirectoryServices - bind to the group in question,
and enumerate its "member" property:

DirectoryEntry deGroup = new
DirectoryEntry("LDAP://cn=YourGroup,ou=YourOU,dc=YourCOmpany,dc=com");

foreach(object oMember in deGroup.Properties["member"])
{
Console.WriteLine(oMember.ToString());
}

This should give you the list of group members, in "DN" format, e.g.

cn=Joe User,ou=YourOU,dc=YourCOmpany,dc=com
cn=Jane User,ou=YourOU,dc=YourCOmpany,dc=com
cn=Jimmy Userr,ou=YourOU2,dc=YourCOmpany,dc=com
cn=Tammy Userr,ou=YourOU2,dc=YourCOmpany,dc=com
........

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
I want my program to create a list of every user in the domain that is
part of a special group. Any ideas?

Check out System.DirectoryServices - bind to the group in question,
and enumerate its "member" property:

DirectoryEntry deGroup = new
DirectoryEntry("LDAP://cn=YourGroup,ou=YourOU,dc=YourCOmpany,dc=com");

foreach(object oMember in deGroup.Properties["member"])
{
Console.WriteLine(oMember.ToString());
}

This should give you the list of group members, in "DN" format, e.g.

cn=Joe User,ou=YourOU,dc=YourCOmpany,dc=com
cn=Jane User,ou=YourOU,dc=YourCOmpany,dc=com
cn=Jimmy Userr,ou=YourOU2,dc=YourCOmpany,dc=com
cn=Tammy Userr,ou=YourOU2,dc=YourCOmpany,dc=com
.......

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch

How do I know what ou and dc to use? Where do I find that information?

As you might have figured out, I'm new to Active Directory and LDAP, so
if you have any good references on the net that might explain the
basics...
 
How do I know what ou and dc to use?

No - how could I - that's *YOUR* directory! ;-)
Where do I find that information?

In the directory, silly ;-) But I agree - it can be a bit tricky to
find these things, if you don't know what they are.

Suggestion: download one of my ADSI browsers, they should give you an
idea of what your directory is, and what kind of OU's and DC's you
have.

http://adsi.mvps.org/adsi/Delphi/adsibrowser.html
http://adsi.mvps.org/adsi/CSharp/beavertail.html

Enjoy!

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top