Accessing Active Directory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I want to access via VB.Net the active directory
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users..

Anyone can help me? Please...

Michele
 
Check out the System.DirectoryServices Namespace

MIchele said:
Hi,
I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also
the exchange mailbox of each users...
 
I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users...

All users across all OU's in your AD ?? There could be many....

THis is C# - should be easy to convert to VB.NET - you'll need to use
the DirectorySearcher class:

DirectorySearcher oSrch = new DirectorySearcher("");

oSrch.Filter = "(&(objectClass=user)(objectCategory=user))";
oSrch.SearchScope = SearchScope.Subtree;

oSrch.PropertiesToLoad.Add("givenName");
oSrch.PropertiesToLoad.Add("sn");
oSrch.PropertiesToLoad.Add("mail");

foreach(SearchResult oRes in oSrch.FindAll())
{
Console.WriteLine("User: " +
oRes.Properties["givenName"].Value.ToString() + " " +
oRes.Properties["sn"].Value.ToString() + " / E-Mail: " +
oRes.Properties["mail"].Value.ToString();
}

It searches the directory, load the "givenName" and "sn" (Surname") as
well as "mail" (e-mail address) properties for the search results, and
loops through the results.

For groups, you'll just need to adjust the filter accordingly.

Marc
 
Here is your starting point:

Dim enTry As DirectoryEntry = New DirectoryEntry(LDAP://<DomainNameHere>)
Console.WriteLine("Active Directory Information")
Console.WriteLine("===========================================")
For Each resEnt As DirectoryEntry In enTry.Children
If (resEnt.SchemaClassName().Equals("organizationalUnit")) Then
Console.WriteLine(resEnt.Name.ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Path.ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().NativeGuid.ToString())
Console.WriteLine("===========================================")
Else
Debug.WriteLine(resEnt.SchemaClassName().ToString())
End If
Next

Don't forget a reference to the System.DirectoryServices namespace, and be sure to use your domain name in the code.

-Enjoy!!

-Evan
 
Back
Top