Command line active directory query email address for username

Solution 1:

dsquery user -name "user name"|dsget user -samid -email -display 

Solution 2:

dsquery user -name "Firstname Lastname" | dsget user -email


Solution 3:

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.


Solution 4:

something like this dsquery might work.

query email by username dsquery.exe * -filter "(&(objectClass=user)(!(objectClass=computer)(sAMAccountName=username)))" | dsget user -email

I misread the post first and thought you wanted user name from email name. That's why i posted this one. dsquery.exe * -filter "(&(objectClass=user)(!(objectClass=computer)([email protected])))" -attr username

based on some scripts at work and this site which has some other ideas http://www.petri.co.il/forums/showthread.php?t=18464 about using csvde.exe


Solution 5:

adfind -sc u:"username" mail