Using the Active Directory command-line tools, in a Windows 2000 domain, or Windows Server 2003 domain, I have scripted NoManager.bat to display all the distinguished names of domain users who have no Manager configured.
The syntax for using NoManager.bat is:
NoManager
The output is displayed on the CMD console, but you can pipe it to a file using the following syntax:
NoManager>FileName
You can use the output in subsequent commands, as in:
for /f "Tokens=*" %%i in ('NoManager') do SomeCommand %%i
NoManager.bat contains:
@echo off setlocal if exist "%TEMP%\NoManager.TM1" del /q "%TEMP%\NoManager.TM1" if exist "%TEMP%\NoManager.TM2" del /q "%TEMP%\NoManager.TM2" set query=dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*))" -attr distinguishedName manager -limit 0 for /f "Tokens=*" %%u in ('%query%') do set line=%%u&call :parse if not exist "%TEMP%\NoManager.TM1" goto done sort "%TEMP%\NoManager.TM1" /O "%TEMP%\NoManager.TM2" type "%TEMP%\NoManager.TM2" del /q "%TEMP%\NoManager.TM1" del /q "%TEMP%\NoManager.TM2" :done endlocal exit /b 0 :parse if /i "%line:~0,17%" NEQ "distinguishedName" goto detail set /a pos=17 :loop set /a pos=%pos% + 1 call set work=%%line:~%pos%^,8%% if /i "%work%" NEQ " manager" goto :loop set /a pos=%pos% + 1 set /a len=%pos% - 2 goto :EOF :detail call set mgr=%%line:~%pos%%% if "%mgr:~0,8%" NEQ " " goto :EOF call set dn="%%line:~0,%len%%%" set dn=%dn: =% set dn=%dn: =% set dn=%dn: "="% @echo %dn%>>"%TEMP%\NoManager.TM1"
0 comments
Hide comments