Active Directory groups

  • Thread starter Maziar Aflatoun
  • Start date
M

Maziar Aflatoun

Hi everyone,

I have the following code that basically reads all information about a
domain user.
System.DirectoryServices.DirectoryEntry entry = new
System.DirectoryServices.DirectoryEntry("LDAP://" + dom, "myusername",
"password", AuthenticationTypes.Secure);
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher(entry);

// Change this to search for anything
mySearcher.Filter = ("(sAMAccountName=myusername)");



System.DirectoryServices.SearchResult resEnt = mySearcher.FindOne();
try
{
System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();
Console.WriteLine("Display Name : " +
de.Properties["DisplayName"].Value.ToString());
Console.WriteLine("User Name : " +
de.Properties["sAMAccountName"].Value.ToString());
Console.WriteLine("First Name : " +
de.Properties["GivenName"].Value.ToString());
Console.WriteLine("Last Name : " + de.Properties["sn"].Value.ToString());
Console.WriteLine("Department : " +
de.Properties["Department"].Value.ToString());
}

Does anyone know I can modify this code to view all the groups that a member
falls under?

Thank you
Maziar A.
 
E

Eric Cadwell

Try this:


private void EnumerateGroups(LDAPpath)

{

DirectoryEntry userAccount = new DirectoryEntry(LDAPpath);

Console.WriteLine("user {0} is a member of:", userAccount.Name);

foreach(string member in user.Properties["memberOf"])

{

Console.WriteLine(member);

}

}



HTH;
Eric Cadwell
http://www.origincontrols.com
 
M

Marc Scheuner [MVP ADSI]

I have the following code that basically reads all information about a
domain user.

Also, for Active Directory related queries, you might want to check
the microsoft.public.adsi.general newsgroup - that's where all the
experts hang out ;-)

Marc

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top