Directory Services |
This is a small application that produces a fully functional System.DirectoryServices console. This application searches Active Directory based on an ambiguous name, which could be a user name, user's first name, user's last name, telephone Number, or office location, and displays the result. This application is created in Visual Studio .NET.
Creating a System.DirectoryServices Console Application
[C#]
using System.DirectoryServices;
...
DirectorySearcher src = new DirectorySearcher("(anr=putANameHere)");
foreach(SearchResult res in src.FindAll() )
{
Console.WriteLine("{0} {1}", res.Properties["cn"][0], res.Properties["telephoneNumber"][0]);
}
[Visual Basic .NET]
Imports System.DirectoryServices
....
Dim src As DirectorySearcher = New DirectorySearcher("(anr=putANameHere)")
Dim result As SearchResult
For Each result In src.FindAll()
Console.WriteLine("{0} {1}", result.Properties("Name")(0), result.Properties("telephoneNumber")(0))
Next
For more information and a code example of a System.DirectoryServices application that uses a Windows form, see Enumerating User Memberships.