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.)
dsquery user -name "Firstname Lastname" | dsget user -email
If the email that you want is also the User Principal Name, you can get it with
However, this only works to get the email of the current user, not any user as the question originally postulated.
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
adfind -sc u:"username" mail
Install Powershell, and the QuestAD addon pack. Then it is something like:
You can write simple VBScript to query thru LDAP Create a file with VBS extension
Put inside something like this
Put correct USER NAME into LDAP query string, run VBS file and enjoy :)
If it is your first time you work with LDAP, it could be a little bit complicated to write LDAP query In order to recognize the LDAP path to the user (i.e. what you need to put after LDAP://) you may download Active Directory Explorer from Microsoft Run explorer, navigate to the user and see what it shows in the Path text box
In my case it was something like CN=[user name],CN=Users,DC=[city_name],DC=[company_name],DC=com,
LINQ to everything! For convenience:
1) In query properties of LinqPad, add a reference to System.DirectoryServices.AccountManagement.dll. 2) Additional Namespace Import: System.DirectoryServices.AccountManagement
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
To get global environment variables in windows we can use "setx" in windows 7. (For loginscript perhaps... but much slower.)
: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.
I don't know it's matched to the thread starter mean or not. But I just find a solution of my existing problem that was already solved after browse this thread. Finding USER LOGIN ID based on KNOWN MAIL ADDRESS. :)
File [salesforce-uid-mail-address.txt] contains list of e-mail addresses. File [salesforce-uid-cn.txt] contains "complete CN with path". And file [salesforce-uid-samid.txt] contains "found SAMID" alias "user login name". That's all folks. Any ideas for improvement are welcome. :)