사용자 이름에 대한 명령 행 활성 디렉토리 조회 이메일 주소


18

Active Directory 환경의 Windows XP-명령 줄에 사용자 이름이 지정된 AD에서 사용자의 전자 메일 주소를 쿼리하는 가장 쉬운 방법은 무엇입니까?

(일반적으로 나무에서 어디에 보관되어 있는지 알고 있다고 가정합니다).

(순 사용자 로그인 이름 / 도메인 에 대해서는 알고 있지만 이메일 주소 요소를 다시 원합니다.)


3
복잡한 Exchange 환경에있는 경우 "메일"속성이 원하는 이메일 주소가 아닐 수 있습니다. 또한 사용자 개체에서 다중 값 특성 "proxyAddresses"를 확인해야합니다.
Ryan Fisher

답변:


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

그렇게 많이
그리워

1
좋아-아마 분명하지 않았지만-당신은 충분히 가깝다-내가 원하는 것 : dsquery user -samid "loginname"| dsget user -email
Hawkeye


5

이 dsquery와 같은 것이 작동 할 수 있습니다.

사용자 이름으로 전자 메일 쿼리 dsquery.exe * -filter "(& (objectClass = user) (! (objectClass = computer) (sAMAccountName = username)))"| dsget 사용자-이메일

글을 먼저 읽었으며 이메일 이름에서 사용자 이름을 원한다고 생각했습니다. 이것이 내가 이것을 게시 한 이유입니다. dsquery.exe * -filter "(& (objectClass = user) (! (objectClass = computer) (mail=user@domain.com)))"-attr 사용자 이름

직장에서 일부 스크립트 와이 사이트를 기반으로 http://www.petri.co.il/forums/showthread.php?t=18464 csvde.exe 사용에 대한 아이디어



4

원하는 이메일이 사용자 프린시 펄 이름 인 경우

whoami /upn

그러나 이것은 원래 사용자의 질문이었던 사용자가 아닌 현재 사용자의 전자 메일을 가져 오는 것만 가능합니다.


대상 사용자로 cmd를 실행하여이 방법을 사용했습니다. 매력처럼 일함
Daniel

1
또한 AD 도메인이 .local이거나 등록 된 공용 도메인이 아닌 유사한 도메인 인 경우 UPN 만 반환합니다. 이는 사용자의 기본 공용 전자 메일 주소와 반드시 같을 필요는 없습니다.
Craig

1
@Craig 내 대답의 첫 번째 문장은 ...
krispy

2

Powershell 및 QuestAD 애드온 팩을 설치하십시오. 그런 다음과 같습니다

connect-qadservice
(get-qaduser 'bobsusername').emailAddress

2

간단한 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,


2

LINQ 에 대한 모든 것을 ! 편의상:

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();

2

내가 원하는 것을 얻는 데 도움이되는이 스레드를 찾았습니다. 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"를 사용할 수 있습니다. (로그인 스크립트의 경우 ...하지만 훨씬 느립니다.)

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의 set-statement 끝에 공백 문자가 있으면 값이 공백으로 끝납니다. 수정하기 위해 제거했습니다. (Set %% A = %% B & setx ...) 또한 스크립트가 제대로 작동하려면 적어도 두 개의 속성을 내 보내야한다는 것을 알았습니다.

응답이 늦었지만, 누군가를 도울 수 있다면 행복합니다.


1

나는 그것이 스레드 스타터 평균과 일치하는지 여부를 모른다. 그러나이 스레드를 탐색 한 후에 이미 해결 된 기존 문제의 해결책을 찾으십시오. KNOWN MAIL 주소를 기반으로 사용자 로그인 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 ] 파일 에는 "found SAMID"별칭 "user login name"이 포함되어 있습니다. 그게 다야 개선을위한 아이디어는 환영합니다. :)


-1

아래는 내가 다른 것을 위해 작성한 배치 스크립트이지만 너무 많은 문제없이 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


거기에는 많은 작업이 있으며 스크립트는 작성된 환경에서 유용 할 것입니다.하지만 IP 입력이 필요하지 않고 올라간 다른 짧은 답변보다 질문에 더 잘 대답하는 방법을 알 수 없습니다. 여기에 몇 년 동안 (허용 된 경우 7 개 이상). 귀하의 방문을 환영하는 더 최근의 답변이없는 질문이 있습니다!
법률 29
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.