Question: On Windows XP in an Active directory environment - what is the easiest way for me to query a user's email address from AD given their username on the command line. 

(Assuming I know where it is kept normally in tree). 

(I know about net user *loginname* /domain but I just want the email address element back.)

Answer: 
```
dsquery user -name "user name"|dsget user -samid -email -display 

```
[LINQ](http://www.linqpad.net/) to [everything](http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2010/08/20/linqpad-and-active-directory.aspx)! For convenience:

1) In query properties of LinqPad, add a reference to System.DirectoryServices.AccountManagement.dll.
2) Additional Namespace Import: System.DirectoryServices.AccountManagement

```
using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "MyDomain))
  using(UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "MyUserID"))
        usr.Dump();

```