JSI Tip 7724. How do I process a multi-line attribute?

Jerold Schulman

February 3, 2004

2 Min Read
ITPro Today logo in a gray background | ITPro Today


NOTE: This tip is superseded by tip 7995.

In tip 7722, I scripted the DSQUERY Filter Extender.

If your query includes a multi-line attribute, like streetAddress, DSQUERY does NOT maintain the report position on the 2nd (and greater) attribute value. For example, if you script:

set query=dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=j*))" -attr sAMAccountName streetAddress -limit 0for /f "Tokens=1* Delims=:" %%q in ('%query% ^|Findstr /l /n /v /c:"*$"') do @echo %%r

The output might look like:

  sAMAccountName    streetAddress  Jerry             123 Smith Street  Jennifer          456 Jones StreetApt. 987  John              789 Front Street

Notice that Apt. 987, Jennifer's 2nd address line, is not in the streetAddress position.

When you use the DSQFE.bat script, it returns a status of M when it detects the 2nd (nth) line of a multi-line attribute.

NOTE: You must use the object redirecting form of the FOR command.

NOTE: The multi-line attribute should be the last attribute in the query.

NOTE: I have NOT attempted to handle more than one multi-line attribute in a query.

When DSQFE.bat returns a status of M, you can call DSQFEMV.bat to process the multi-line attribute. DSQFEMV.bat will shift the data to the proper column and properly set the Attribute environment variable in your script.

The syntax for using DSQFEMV.bat is:

call DSQFEMV Table Line Attribute

where:

table     is a call directed environment variable that DSQFE.bat used to store attribute information.line      is a call directed environment variable that contains the multi-line attribute value.Attribute is the name of the multi-line attribute, like streetAddress.

DSQFEMV.bat contains:

@echo offif {%3}=={} goto syntaxset $DSQMVs=                                                                                                                  #set /a $DSQMVln=0set /a $DSQFEtp=0:tloopcall set $DSQFEw=%%%1:~%$DSQFEtp%^,50%%%if "%$DSQFEw:~0,3%" EQU "###" goto finishset $DSQFEw=%$DSQFEw: =%set /a $DSQFEtp=%$DSQFEtp% + 50call set /a $DSQFEp=10000%%%1:~%$DSQFEtp%^,4%%%%%%10000set /a $DSQFEtp=%$DSQFEtp% + 4call set /a $DSQFEl=100%%%1:~%$DSQFEtp%^,2%%%%%%100set /a $DSQFEtp=%$DSQFEtp% + 2if /i "%$DSQFEw%" NEQ "%3" goto tloopcall set $DSQMVl=%%$DSQMVs:~0,%$DSQFEp%%%call set $DSQMVc=%%%2:~0,%$DSQFEl%%%set $DSQMVl=%$DSQMVl%%$DSQMVc%call set %$DSQFEw%=%%%2%%###call set %$DSQFEw%=%%%$DSQFEw%:  =%%%call set %$DSQFEw%=%%%$DSQFEw%: ###=###%%%call set %$DSQFEw%="%%%$DSQFEw%:###=%%%"goto tloop:finishset %2=%$DSQMVl%exit /b 0:syntax@echo Syntax:  call DSQFEMV Table Line Attributeexit /b 1



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like