views:

42

answers:

1

My company is a Microsoft shop (Exchange, AD, etc.).

I'd like to do queries on our employee directory like:

Person person = directory.Lookup("jsmith");
string title = person.Fields("JobTitle");
Person manager = person.GetManager();
if (person.IsManager())
{
    Person[] subordinates = person.GetSubordinates();
}

Is there any easy way to do something like this? I intend to do it on an informal basis in scripts, not in shipping code.

+2  A: 

I've never used this but it looks interesting:

Linq to Active Directory

The give an example:

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();
Christopher Painter