Using the Active Directory command-line tools, in a Windows 2000 domain, or Windows Server 2003 domain, I have scripted Manager.bat to list "Department";"Manager";"UserDistinguishedName" in my domain.
The syntax for using Manager.bat is:
Manager
NOTE: See:
What user accounts in my domain have no Manager configured?
What user accounts in my domain have no Department configured?
The output is displayed on the CMD console, but you can pipe it to a file using the following syntax:
Manager>FileName
You can use the output in subsequent commands, as in:
for /f "Tokens=1-3 Delims=;" %%i in ('Manager') do SomeCommand %%i %%j %%k
Manager.bat contains:
@echo off setlocal if exist "%TEMP%\Manager.TM1" del /q "%TEMP%\Manager.TM1" if exist "%TEMP%\Manager.TM2" del /q "%TEMP%\Manager.TM2" set query=dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*))" -attr distinguishedName department manager -L -limit 0 for /f "Tokens=1* Delims=: " %%u in ('%query%') do set field=%%u&set line=%%v&call :parse if not exist "%TEMP%\Manager.TM1" goto done sort "%TEMP%\Manager.TM1" /O "%TEMP%\Manager.TM2" type "%TEMP%\Manager.TM2" del /q "%TEMP%\Manager.TM1" del /q "%TEMP%\Manager.TM2" :done endlocal exit /b 0 :parse if /i "%field%" EQU "distinguishedName" set dn="%line%"&goto :EOF if /i "%field%" EQU "department" set dpt="%line%"&goto :EOF if /i "%field%" EQU "manager" set mgr="%line%" @echo %dpt%;%mgr%;%dn%>>"%TEMP%\Manager.TM1"
0 comments
Hide comments