Using the Active Directory command-line tools, in a Windows 2000 domain, or Windows Server 2003 domain, I have scripted TelDir.bat to produce a telephone directory.

The syntax for using TelDir.bat is:

teldir ReportFile Lines \[/x:exlusions\] \[/n:nn\] \[/o:nn\] \[/t:nn\] \[/i:nn\] \[/e:nn\]

where:

<b>ReportFile</b>      is the file name of the telephone directory report.

<b>Lines</b>           is the number of lines to print per page.
                It must be less than the number that can be printed before a <b>Print ReportFile</b> command auto-paginates.
                If you print the report landscaped, the number should reflect this.

<b>/x:exlusions</b>    is a list of fields to exclude, using the following table:<pre>                        <b>Exclude  Field            Explanation</b>
                        <b>B</b>        N/A              Only the first heading line is printed.
                        <b>E</b>        E-mail Address
                        <b>F</b>        Fax Number
                        <b>H</b>        Home Phone
                        <b>I</b>        IP Phone
                        <b>M</b>        Mobile Phone
                        <b>O</b>        Office Name
                        <b>P</b>        Pager Number
/n:nn will set the number of characters in the Name column. The default is 33. The minimum is 15. /o:nn will set the number of characters in the Office column. The default is 12. The minimum is 2. /t:nn will set the number of characters in all telephone number columns. The default is 15. The minimum is 7. /i:nn will set the number of characters in the IpTel column. The default is 24. The minimum is 7. /e:nn will set the number of characters in the Email column. The default is 24. The minimum is 10.

Sample Usage:

<b>TelDir "%UserProfile%\Documents and Settings\TelDir.txt" 60</b>  Will generate the complete report.

<b>TelDir teldir.txt 58 /x:b</b>                                    Will generate the complete report. Only the first record has column headings.

<b>TelDir c:\folder\report.txt 58 /x:IHF</b>                        The report will exclude the <b>IpTel</b>, <b>Home</b>, and <b>Fax</b> columns.

<b>TelDir c:\folder\report.txt 58 /x:I /N:30 /O:10 /E:17 /T:14</b>  The report will exclude the <b>IpTel</b> column.
                                                             The <b>Name</b> column will contain 30 characters,
                                                             the <b>Office</b> column will contain 10 characters,
                                                             the <b>Email</b> column will contain 17 characters,
                                                             and all the telephone number columns will contain 14 characters.
Here is a portion of a complete report, generated with no exclusions or column sizing changes:
<font size="1">............ S ............

Name                              Office       Phone           Mobile          Pager           Fax             Email                    IpTel                    Home          

Schulman, Jennifer V.             Corporate    1 770 475 XXXX  1 XXX XXX XXXX  1 XXX XXX XXXX  1 XXX XXX XXXX  Jennifer@JSIINC.COM                               1 XXX XXX XXXX
Schulman, Jerold                  Corporate    1 770 475 3820  1 678 362 4762  1 XXX XXX XXXX  1 770 442 3820  Jerry@JSIINC.COM                                  1 XXX XXX XXXX</font>
NOTE: You must download ff.com and place it in the %SystemRoot% folder. This file contains a form feed.

TelDir.bat contains:

@echo off
if not exist "%systemroot%\ff.com" @echo "%systemroot%\ff.com" is missing.&goto :EOF
setlocal
if \{%2\}<h1><a name="_goto_syntax_if_exist_TEMP_teldir_tm1_del_q_TEMP_teldir_tm1_set_report_1_if_exist_report_del_q_report_set_a_lp_1000_2_1000_set_a_lc_0_shift_shift_set_a_nl_33_set_a_ol_12_set_a_tl_15_set_a_il_24_set_a_el_24_set_exclude_#_param_if_1_">\{\} goto syntax
if exist "%TEMP%\teldir.tm1" del /q "%TEMP%\teldir.tm1"
set report=%1
if exist %report% del /q %report%
set /a lp=1000%2%%1000
set /a lc=0
shift
shift
set /a nl=33
set /a ol=12
set /a tl=15
set /a il=24
set /a el=24
set exclude=#
:param
if \{%1\}</a></h1>\{\} goto begin
set p=%1
if /i "%p:~0,3%" EQU "/x:" goto ex
if /i "%p:~0,3%" EQU "/o:" goto off
if /i "%p:~0,3%" EQU "/t:" goto tel
if /i "%p:~0,3%" EQU "/i:" goto ip
if /i "%p:~0,3%" EQU "/e:" goto em
if /i "%p:~0,3%" EQU "/n:" goto nm
goto syntax
:nm
set wrk=%p:~3%
set /a nl=100%wrk%%%100
if %nl% LSS 15 goto syntax
goto paramend
:em
set wrk=%p:~3%
set /a el=100%wrk%%%100
if %el% LSS 10 goto syntax
goto paramend
:ip
set wrk=%p:~3%
set /a il=100%wrk%%%100
if %il% LSS 7 goto syntax
goto paramend
:tel
set wrk=%p:~3%
set /a tl=100%wrk%%%100
if %tl% LSS 7 goto syntax
goto paramend
:off
set wrk=%p:~3%
set /a ol=100%wrk%%%100
if %ol% LSS 2 goto syntax
goto paramend
:ex
set exclude=%p:~3%#
:paramend
shift
goto param
:syntax
@echo Syntax: TelDir ReportFile Lines \[/x:exlusions\] \[/n:nn\] \[/O:nn\] \[/t:nn\] \[/i:nn\] \[/e:nn\]
endlocal
goto :EOF
:begin
set EB=N
set EE=N
set EF=N
set EH=N
set EI=N
set EM=N
set EO=N
set EP=N
set wrk=%exclude:B=%
if "%wrk%" NEQ "%exclude%" set EB=Y
set wrk=%exclude:E=%
if "%wrk%" NEQ "%exclude%" set EE=Y
set wrk=%exclude:F=%
if "%wrk%" NEQ "%exclude%" set EF=Y
set wrk=%exclude:H=%
if "%wrk%" NEQ "%exclude%" set EH=Y
set wrk=%exclude:I=%
if "%wrk%" NEQ "%exclude%" set EI=Y
set wrk=%exclude:M=%
if "%wrk%" NEQ "%exclude%" set EM=Y
set wrk=%exclude:O=%
if "%wrk%" NEQ "%exclude%" set EO=Y
set wrk=%exclude:P=%
if "%wrk%" NEQ "%exclude%" set EP=Y
set wrk=Name                                             #
call set title=%%wrk:~0,%nl%%%
set wrk=Office                      #
if "%EO%" NEQ "Y" call set title=%title% %%wrk:~0,%ol%%%
set wrk=Phone                       #
call set title=%title% %%wrk:~0,%tl%%%
set wrk=Mobile                      #
if "%EM%" NEQ "Y" call set title=%title% %%wrk:~0,%tl%%%
set wrk=Pager                       #
if "%EP%" NEQ "Y" call set title=%title% %%wrk:~0,%tl%%%
set wrk=Fax                         #
if "%EF%" NEQ "Y" call set title=%title% %%wrk:~0,%tl%%%
set wrk=Email                                #
if "%EE%" NEQ "Y" call set title=%title% %%wrk:~0,%el%%%
set wrk=IpTel                                #
if "%EI%" NEQ "Y" call set title=%title% %%wrk:~0,%il%%%
set wrk=Home                        #
if "%EH%" NEQ "Y" call set title=%title% %%wrk:~0,%tl%%%
for /f "Tokens=*" %%u in ('dsquery user domainroot -name * -limit 0') do (
 for /f "Tokens=*" %%t in ('dsget user %%u  -fn -mi -ln -tel -email -hometel -pager -mobile -fax -iptel -office -c -l') do set line=%%t&call :parse
 )
sort "%TEMP%\teldir.tm1" /O "%TEMP%\teldir.tm2"
if "%EB%" EQU "Y" @echo %title%>%report%&set /a lp=999999
set prev=
for /f "Tokens=*" %%t in ('type "%TEMP%\teldir.tm2"') do set line=%%t&call :reportit
del /q "%TEMP%\teldir.tm1"
del /q "%TEMP%\teldir.tm2"
endlocal
goto :EOF
:reportit
if "%EB%" EQU "Y" goto rpt1
if not defined prev goto new
if %lc% EQU %lp% goto new
if /i "%prev%" EQU "%line:~0,1%" goto rpt1
:new
if exist %report% call :copys>nul 2>&1
set /a lc=4
set prev=%line:~0,1%
@echo ............ %prev% ............>>%report%
@echo.>>%report%
@echo %title%>>%report%
@echo.>>%report%
:rpt1
@echo %line%>>%report%
set /a lc=%lc% + 1
goto :EOF
:parse
set line=%line:)= %
set line=%line:(= %
if /i "%line%" EQU "dsget succeeded" goto :out
for /f "Tokens=1* Delims=: " %%p in ('@echo %line%') do set ti=%%p&set data=%%q
if /i "%ti%" EQU "fn" set fn=%data%&goto :EOF
if /i "%ti%" EQU "mi" set mi=%data%&goto :EOF
if /i "%ti%" EQU "ln" set ln=%data%&goto :EOF
if /i "%ti%" EQU "office" set office=%data%&goto :EOF
if /i "%ti%" EQU "tel" set tel=%data%&goto :EOF
if /i "%ti%" EQU "email" set email=%data%&goto :EOF
if /i "%ti%" EQU "hometel" set hometel=%data%&goto :EOF
if /i "%ti%" EQU "pager" set pager=%data%&goto :EOF
if /i "%ti%" EQU "mobile" set mobile=%data%&goto :EOF
if /i "%ti%" EQU "fax" set fax=%data%&goto :EOF
if /i "%ti%" EQU "iptel" set iptel=%data%&goto :EOF
goto :EOF
:copys
copy %report%+"%systemroot%\ff.com" %report%
goto :EOF
:out
if "%ln%" EQU "" goto :EOF
set name=%ln%, %fn% %mi%                                         #
call set text=%%name:~0,%nl%%%
set office=%office%                      #
if "%EO%" NEQ "Y" call set text=%text% %%office:~0,%ol%%%
set tel=%tel%                            #
call set text=%text% %%tel:~0,%tl%%%
set mobile=%mobile%                           #
if "%EM%" NEQ "Y" call set text=%text% %%mobile:~0,%tl%%%
set pager=%pager%                             #
if "%EP%" NEQ "Y" call set text=%text% %%pager:~0,%tl%%%
set fax=%fax%                                 #
if "%EF%" NEQ "Y" call set text=%text% %%fax:~0,%tl%%%
set email=%email%                                     #
if "%EE%" NEQ "Y" call set text=%text% %%email:~0,%el%%%
set iptel=%iptel%                                     #
if "%EI%" NEQ "Y" call set text=%text% %%iptel:~0,%il%%%
set hometel=%hometel%                           #
if "%EH%" NEQ "Y" call set text=%text% %%hometel:~0,%tl%%%
@echo %text%>>"%TEMP%\teldir.tm1"