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: 
If the email that you want is also the User Principal Name, you can get it with

```
whoami /upn

```

However, this only works to get the email of the current user, not any user as the question originally postulated.
Found this thread that helped me get what I wanted. To get any AD users attributes into environment variables. This script takes all wanted attributes from logged in user and sets a corresponding environment variable. I prefixed the variables but that is optional, so variable name becomes "AD[attribute name]". Attributes is of your choice, just add or remove your attribute after -attr. Not very useful for multivalue-attributes though. Last (one) value goes into the environment variable.

This script is local to current cmd.exe

```
for /F "tokens=1,* delims=: " %%A in ('dsquery * domainroot -l -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%USERNAME%))" -attr adminDescription employeetype company department physicalDeliveryOfficeName street title mail') do set AD%%A=%%B

```

To get global environment variables in windows we can use "setx" in windows 7. (For loginscript perhaps... but much slower.)

```
for /F "tokens=1,* delims=: " %%A in ('dsquery * domainroot -l -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%USERNAME%))" -attr adminDescription employeetype company department physicalDeliveryOfficeName street title mail') do set AD%%A=%%B& setx AD%%A "%%~B" > NUL

```

:EDIT: a space character at end of set-statement in example 2 caused value to end with empty space. Removed it to correct. ( Set %%A=%%B& setx... )
Also found out that you must export at least two attributes for script to work properly.

A late responce, but if it can help anyone out there I'm happy.