Your submission was: "!resourcein!"Įcho !resource! has been copied to the clipboard and is ready to paste.If you show some initiative, I can help in VBS. :: - Black background with red font (amiga guru looking error) -Įcho Sorry, it appears you've entered an CN that's either not forĮcho !envtype!, has not got anything in it's attribute or has been copied incorrectly!Įcho. IF NOT %resource%= GOTO RESULT :: Resource value has something then send to the result step otherwise default to error :: - Extraction of the attribute from the output file -įor /f "delims=" %%a in (output.txt) do ( :: pause :: only have this line active (start colons missing) during troubleshooting to see if anything is written to the output.txt file Ldifde -s %servip% -t %servpt% -a -d "" -f output.txt -l "" -r "(cn=%resource%)" Setlocal enableextensions enabledelayedexpansionĮcho Please enter the number of the environment you wish to search and press enter or type q and press enter to quit: (3)Įcho Copy and paste the CN and press enter (or type q and enter to quit): :: default choice (1 preproduction 2 test 3 production) :: - careful with this as it'll need to be a generic account with a non-expiring off :: - anything in is something you need to fill e.g. :: - It was written to translate a hashed CN with it's more human readable attribute.
![vbscript ldap query user attributes vbscript ldap query user attributes](https://thesysadminchannel.com/wp-content/uploads/2021/10/Get-ADUser-SearchBase.png)
:: - Purpose: A simple lookup batch script using the ldifde command. :)īelow is a batch script I wrote for something else but it can be used to find the e-mail attribute within a CN without too much issue. And file contains "found SAMID" alias "user login name". :) C:\Users\MrCMD>for /f "delims=" %u in ('type salesforce-uid-mail-address.txt') do * -filter "(&(objectClass=user)(!(objectClass=computer)(mail=%u)))">"salesforce-uid-cn.txt"Ĭ:\Users\MrCMD>for /f "delims=" %u in ('type salesforce-uid-cn.txt') do user %u -samid -l|find "samid" /i>"salesforce-uid-samid.txt"įile contains list of e-mail addresses. Finding USER LOGIN ID based on KNOWN MAIL ADDRESS. But I just find a solution of my existing problem that was already solved after browse this thread. I don't know it's matched to the thread starter mean or not. )Īlso found out that you must export at least two attributes for script to work properly.Ī late responce, but if it can help anyone out there I'm happy. :EDIT: a space character at end of set-statement in example 2 caused value to end with empty space. 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
#VBSCRIPT LDAP QUERY USER ATTRIBUTES WINDOWS#
To get global environment variables in windows we can use "setx" in windows 7. 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 Last (one) value goes into the environment variable. Not very useful for multivalue-attributes though.
![vbscript ldap query user attributes vbscript ldap query user attributes](https://techgenix.com/content/mse/img/upl/image0081112015329237.jpg)
Attributes is of your choice, just add or remove your attribute after -attr.
![vbscript ldap query user attributes vbscript ldap query user attributes](https://devblogs.microsoft.com/wp-content/uploads/sites/29/2019/02/5074.01.png)
I prefixed the variables but that is optional, so variable name becomes "AD". This script takes all wanted attributes from logged in user and sets a corresponding environment variable. To get any AD users attributes into environment variables. Found this thread that helped me get what I wanted.