Archive for January 21st, 2010

C# AD search

January 21st, 2010 | Category: Windows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
// Bind to the container to enumerate.
DirectoryEntry ent = new DirectoryEntry(”LDAP://OU=Users,DC=Domain,DC=local”);
// Create an object to use for individual objects in the container and iterate
// through the container.
foreach (DirectoryEntry child in ent.Children)
{
// Write the name and path for each object in the container.
Console.WriteLine(”{0} {1}”, child.Name, child.Path);
}

}
catch
{
// Handle errors.
}

}
}
}

No comments