JSI Tip 7995. Fix for DSQUERY multi-line attribute.


When you use the DSQUERY * command to generate a report, it is nicely formatted, except the presence of a multi-line attribute destroys the heading / data alignment, as in:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=t*))" -attr sAMAccountName streetAddress l postalCode co

  sAMAccountName      streetAddress                 l             postalCode    co
  test1               123 Smith Street              Atlanta       30338         United States
  test2               456 Jones Street
Suite 120                     Atlanta       30338         United States
  test3               789 Brown Street              Atlanta       30338         United States

I have scripted JSIDSQry.bat, so that running

JSIDSQry * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=t*))" -attr sAMAccountName streetAddress l postalCode co

reports

  sAMAccountName      streetAddress                 l             postalCode    co
  test1               123 Smith Street              Atlanta       30338         United States
  test2               456 Jones Street
                      Suite 120                     Atlanta       30338         United States
  test3               789 Brown Street              Atlanta       30338         United States
JSIDSQry.bat contains:
@echo off
if \{%1\}==\{\} @echo Syntax: JSIDSQry DsqueryParams&exit /b 0
setlocal
set dsq=dsquery %*
set dsqm=%dsq%
set HD=Y
set spaces=                                                    #
set blank=%spaces:~0,50%
set blank=%blank%%blank%%blank%%blank%
call :ParseHD>nul 2>&1
call :AttrLoop "%HDLine%#####"
for /f "Tokens=1" %%f in ('@echo %HDline%') do (
 set NewLine=%%f
)
@echo\ %HDline%
set dsqm=%dsq% -L
set HD=Y
for /f "Tokens=1*" %%a in ('%dsqm%') do (
 set attrib=%%a
 set data=%%b
 call :Report
)
@echo\ %line%
endlocal
exit /b 0
:ParseHD
for /f "Tokens=*" %%a in ('%dsqm%') do (
 call :ParseHD1 %%a
)
goto :EOF
:ParseHD1
if "%HD%" EQU "N" goto :EOF
set HD=N
set HDLine=%*
goto :EOF
:AttrLoop
set HDLine=%HDline:#####"=%
set headtab=0000
set /a cnt=0
set /a seq=0
:head
set /a seq=%seq% + 1
call set char=%%HDline:~%seq%^,1%%
if "%char%" EQU "" goto head9
if "%char%" EQU " " goto head1
goto head
:head1
set /a seq=%seq% + 1
call set char=%%HDline:~%seq%^,1%%
if "%char%" EQU "" goto head9
if "%char%" EQU " " goto head1
set /a point=%cnt% * 8
call set pos=%%headtab:~%point%^,4%%
set /a pos=10000%pos%%%10000
set /a len=%seq% - %pos% -1
set /a len=%len% + 10000
set /a nxt=%seq% + 10000
set headtab=%headtab%%len:~1,4%%nxt:~1,4%
set /a cnt=%cnt% + 1
goto head
:head9
set headtab=%headtab%0000%nxt:~1,4%2047
goto :EOF
:Report
set work=%attrib::=%
if "%HD%" EQU "Y" set HD=N&goto Report1
if /i "%work%" NEQ "%NewLine%" goto Report2 
@echo\ %line%
:Report1
set line=
set /a cnt=0
:Report2
if "%work%" NEQ "%attrib%" goto Report3 
@echo\ %line%
set line=%blank%%blank%%blank%%blank%
set /a cnt=%cnt% - 1
set /a seq=%cnt% * 8
call set char=%%headtab:~%seq%^,8%%
set /a pos=10000%char:~0,4%%%10000
call set char=%%line:~0,%pos%%%
set line=%char%
set data=%attrib%
:Report3
set /a seq=%cnt% * 8
set /a cnt=%cnt% + 1
call set char=%%headtab:~%seq%^,8%%
set /a pos=10000%char:~0,4%%%10000
set /a len=10000%char:~4,4%%%10000
If %len% EQU 0 set line=%line%%data%&goto :EOF
set data=%data%%blank%
call set char=%%data:~0,%len%%%
set line=%line%%char% 



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish