I have found an amazing LINQ to AD open source assembly. Makes life for programming AD very easy here is a sample.
// NOTE: Entity type definition "User" omitted in sample - see samples in release.
var users = new DirectorySource<User>(ROOT, SearchScope.Subtree);
users.Log = Console.Out;
var res = from usr in users
where usr.FirstName.StartsWith("B") && usr.Office == "2525"
select new { Name = usr.FirstName + " " + usr.LastName, usr.Office, usr.LogonCount };
foreach (var u in res)
{
Console.WriteLine(u);u.Office = "5252";
u.SetPassword(pwd);
}
users.Update();
Look at how simple that is, if anyone is confused the var is an object created by the LINQ class so you just use it as any normal type. The good thing about this class is that changing any kind of property is very easy and straight forward.
If you don’t understand LINQ very well here is a URL for some help.
http://msdn.microsoft.com/en-us/netframework/aa904594.aspx
Download the LINQ to AD source
http://www.codeplex.com/LINQtoAD/Release/ProjectReleases.aspx?ReleaseId=8629