By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

Accessing Active Directory

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Check out the System.DirectoryServices Namespace

"MIchele" <mm******@omniway.sm> wrote in message
news:BD**********************************@microsof t.com...
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

Jul 21 '05 #2

P: n/a
Check out the System.DirectoryServices Namespace

"MIchele" <mm******@omniway.sm> wrote in message
news:BD**********************************@microsof t.com...
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

Jul 21 '05 #3

P: n/a
>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

Jul 21 '05 #4

P: n/a
>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

Jul 21 '05 #5

P: n/a
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("organizationalUn it")) Then
Console.WriteLine(resEnt.Name.ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Path .ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Nati veGuid.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
"MIchele" <mm******@omniway.sm> wrote in message news:BD**********************************@microsof t.com...
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

Jul 21 '05 #6

P: n/a
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("organizationalUn it")) Then
Console.WriteLine(resEnt.Name.ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Path .ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Nati veGuid.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
"MIchele" <mm******@omniway.sm> wrote in message news:BD**********************************@microsof t.com...
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

Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.