Answers:
dsquery user -name "user name"|dsget user -samid -email -display
这样的dsquery可能会起作用。
通过用户名dsquery.exe查询电子邮件* -filter“(&(objectClass = user)(!(objectClass = computer)(sAMAccountName = username)))” | dsget用户-email
我首先误读了该帖子,并认为您希望使用电子邮件名中的用户名。这就是为什么我发布了这个。dsquery.exe * -filter“(&(objectClass = user)(!(objectClass = computer)(mail=user@domain.com)))” -attr用户名
基于工作中的一些脚本以及此站点,该站点还有其他一些有关使用csvde.exe的想法http://www.petri.co.il/forums/showthread.php?t=18464
您可以编写简单的VBScript以通过LDAP查询创建带有VBS扩展名的文件
放入这样的东西
On Error Resume Next
Set objUser = GetObject _
("LDAP://CN=USER NAME,DC=DOMAIN_NAME,DC=com")
objUser.GetInfo
strMail = objUser.Get("mail")
WScript.echo "mail: " & strMail
将正确的用户名放入LDAP查询字符串中,运行VBS文件并享受:)
如果您是第一次使用LDAP,那么编写LDAP查询可能会有些复杂。为了识别用户的LDAP路径(即,您需要在LDAP://之后输入的内容),您可以下载Active Directory从Microsoft Run Explorer的资源管理器中,导航到该用户并查看其在“路径”文本框中显示的内容
在我的情况下,它类似于CN = [user name],CN = Users,DC = [city_name],DC = [company_name],DC = com,
1)在LinqPad的查询属性中,添加对System.DirectoryServices.AccountManagement.dll的引用。2)额外的命名空间导入:System.DirectoryServices.AccountManagement
using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "MyDomain))
using(UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "MyUserID"))
usr.Dump();
找到了这个线程,可以帮助我得到想要的东西。要将所有AD用户属性添加到环境变量中。该脚本从登录用户获取所有需要的属性,并设置相应的环境变量。我为变量添加了前缀,但这是可选的,因此变量名称变为“ AD [attribute name]”。您可以选择属性,只需在-attr之后添加或删除属性。但是对于多值属性不是很有用。最后(一个)值进入环境变量。
该脚本是当前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
要在Windows中获取全局环境变量,我们可以在Windows 7中使用“ setx”。(对于loginscript,也许……但要慢得多。)
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:示例2中设置语句结尾的空格字符导致值以空白结尾。将其删除以更正。(设置%% A = %% B&setx ...)还发现您必须导出至少两个属性,脚本才能正常工作。
回复晚了,但是如果可以帮助外面的人,我会很高兴。
我不知道它是否与线程启动器的意思相匹配。但是我只是找到了我现有问题的解决方案,在浏览该线程后已经解决了。基于已知邮件地址查找用户登录ID。:)
C:\Users\MrCMD>for /f "delims=" %u in ('type salesforce-uid-mail-address.txt') do @dsquery.exe * -filter "(&(objectClass=user)(!(objectClass=computer)(mail=%u)))">>"salesforce-uid-cn.txt"
┌─────────────────────────────────────┐
│ Executed Wed 07/10/2013 8:29:55.05 │ As [MrCMD]
└─────────────────────────────────────┘
C:\Users\MrCMD>for /f "delims=" %u in ('type salesforce-uid-cn.txt') do @dsget.exe user %u -samid -l|find "samid" /i>>"salesforce-uid-samid.txt"
┌─────────────────────────────────────┐
│ Executed Wed 07/10/2013 8:31:56.40 │ As [MrCMD]
└─────────────────────────────────────┘
文件[ salesforce-uid-mail-address.txt ]包含电子邮件地址列表。文件[ salesforce-uid-cn.txt ]包含“带有路径的完整CN”。文件[ salesforce-uid-samid.txt ]包含“找到的SAMID”别名“用户登录名”。那是所有人。任何改进的想法都欢迎。:)
下面是我为其他内容编写的批处理脚本,但可以将其用于在CN中查找电子邮件属性而不会出现太多问题。
:: CN Attribute Lookup Tool
:: Written by Turbo Dog
::
:: -- Purpose: A simple lookup batch script using the ldifde command.
::
:: -- It was written to translate a hashed CN with it's more human readable attribute.
::
:: -- Multi environment version
::
:: -- anything in <brackets> is something you need to fill e.g. "set servip=10.0.0.5"
::
:: -- Generic ID Version:
:: -- <ID with read access to CN and it's target attribute> will have to be made,
:: -- careful with this as it'll need to be a generic account with a non-expiring password
::
::
:BEGIN
@echo off
:: - Grey background with black font -
color 70
:RESTART
cls
:: Environment choice
:: default choice (1 preproduction 2 test 3 production)
set ENVCH=3
setlocal enableextensions enabledelayedexpansion
echo ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo Û CN Attribute Lookup Tool V1.0 Û
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo.
echo.
echo 1. PreProduction
echo 2. Test
echo 3. Production
echo.
echo Please enter the number of the environment you wish to search and press enter or type q and press enter to quit: (3)
set /p ENVCH=
IF %ENVCH%==1 GOTO PPRODU
IF %ENVCH%==2 GOTO TESTEN
IF %ENVCH%==3 GOTO PRODUC
IF %ENVCH%==q GOTO FINISH
IF %ENVCH%==Q GOTO FINISH
IF %ENVCH%==[%1]==[] GOTO FINISH
:: PreProduction settings
:PPRODU
set envtype=PreProduction
set servip=<IP or hostname of preproduction AD server>
set servpt=<port number of preproduction AD server>
GOTO GATHER
:: Test settings
:TESTEN
set envtype=Test
set servip=<IP or hostname of test AD server>
set servpt=<port number of test AD server>
GOTO GATHER
:: Production settings
:PRODUC
set envtype=Production
set servip=<IP or hostname of production AD server>
set servpt=<port number of production AD server>
GOTO GATHER
:GATHER
:: - Gather information for job -
cls
:: - Grey background with black font -
color 70
echo ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo Û CN Attribute Lookup Tool V1.0 Û
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo Environment - !envtype!
echo.
echo Copy and paste the CN and press enter (or type q and enter to quit):
set /p resource=""
IF "%resource%"=="q" GOTO FINISH
IF "%resource%"=="Q" GOTO FINISH
set resourcein=!resource!
cls
:: - Process action -
ldifde -s %servip% -t %servpt% -a <ID with read access to CN and it's target attribute> <password for ID> -d "<the container that holds the CN's to search through cn=Container,ou=DOMAIN,o=ORG>" -f output.txt -l "<target attribute to read>" -r "(cn=%resource%)"
:: pause :: only have this line active (start colons missing) during troubleshooting to see if anything is written to the output.txt file
cls
:: - Extraction of the attribute from the output file -
set resource=
for /f "delims=" %%a in (output.txt) do (
set line=%%a
if "x!line:~0,22!"=="<target attribute to read>: " (
set resource="!line:~22!"
)
)
:: - Check to see if it has worked? -
IF NOT %resource%==[%1]==[] GOTO RESULT :: Resource value has something then send to the result step otherwise default to error
:: - The error message -
:: - Black background with red font (amiga guru looking error) -
color 0C
cls
echo ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo Û CN Attribute Lookup Tool V1.0 Û
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo Environment - !envtype!
echo.
echo Sorry, it appears you've entered an CN that's either not for
echo !envtype!, has not got anything in it's attribute or has been copied incorrectly!
echo.
echo Press any key to retry.
:: - Cleanup errored output file -
del output.txt
pause >nul
GOTO GATHER
:: - The result -
:RESULT
:: - Copy result to clipboard -
echo|set/p=%resource%|clip
:: - Grey background with black font -
color 70
cls
echo ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo Û CN Attribute Lookup Tool V1.0 Û
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo Environment - !envtype!
echo.
echo. Your submission was: "!resourcein!"
echo The attribute is: !resource!
echo.
echo !resource! has been copied to the clipboard and is ready to paste.
echo.
:: - Cleanup output file -
del output.txt
:: - default to exit -
set fn=n
echo Do you have additional resources to look up (y for yes, n for no and c to change environment)? (n):
set /p fn=""
IF %fn%==y GOTO GATHER
IF %fn%==Y GOTO GATHER
IF %fn%==c GOTO RESTART
IF %fn%==C GOTO RESTART
:FINISH
echo.
echo Thank you, press any key to exit.
pause >nul
:: - Set CMD Shell colours back to default -
color 07
:: - The end -
@echo off
:EOF