JSI Tip 8220. How can I retrieve printer capability information from Active Directory?

Using DSQUERY, I have scripted ADPrinters.bat to retrieve the following printer attributes and generate a CSV file:

printShareName
PrinterName
location
description
shortServerName
printPagesPerMinute
printMaxResolutionSupported
printOrientationsSupported
printColor
printBinNames
printDuplexSupported
printMediaReady
printStaplingSupported
printCollate
printLanguage
The syntax for using ADPrinters.bat is:

ADPrinters CSVFileName

Where CSVFileName is the name of the CSV to generate.

ADPrinters.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: ADPrinters CSVFileName&goto :EOF
setlocal
set csvfile=%1
if exist %csvfile% del /q %csvfile%
set qry1=dsquery * domainroot -filter "(&(objectClass=PrintQueue))" -attr
set qry2= printShareName PrinterName location description shortServerName printPagesPerMinute printMaxResolutionSupported
set qry3= printOrientationsSupported printColor printBinNames printDuplexSupported printMediaReady printStaplingSupported
set qry4= printCollate printLanguage -L -limit 0
set qry=%qry1%%qry2%%qry3%%qry4%
set share=ShareName
set name=PrintName
set loc=Location
set desc=Description
set srv=Server
set ppm=PPM
set res=DPI
set orient=Orientations
set bins=Trays
set color=Color
set paper=Paper
set dpx=Duplex
set stp=Staple
set coll=Collate
set lng=Language
for /f "Tokens=1* Delims=:" %%a in ('%qry%') do (
 set attr=%%a
 set data=%%b
 call :build
)
call :output
endlocal
goto :EOF
:build
if /i "%attr%" EQU "printShareName" call :output
set data=%data:~1%
if "%data%" NEQ "" set data=%data:"=%
if "%data%" NEQ "" set data=%data:,=%
if "%data%" NEQ "" set data=%data:^:=%
if /i "%data%" EQU "TRUE" set data=T
if /i "%data%" EQU "FALSE" set data=F
if "%data%" EQU "" set data=
if /i "%attr%" EQU "PrinterName" set name=%data%&goto :EOF
if /i "%attr%" EQU "location" set loc=%data%&goto :EOF
if /i "%attr%" EQU "description" set desc=%data%&goto :EOF
if /i "%attr%" EQU "shortServerName" set srv=%data%&goto :EOF
if /i "%attr%" EQU "printPagesPerMinute" set ppm=%data%&goto :EOF
if /i "%attr%" EQU "printColor" set color=%data%&goto :EOF
if /i "%attr%" EQU "printDuplexSupported" set dpx=%data%&goto :EOF
if /i "%attr%" EQU "printStaplingSupported" set stp=%data%&goto :EOF
if /i "%attr%" EQU "printCollate" set coll=%data%&goto :EOF
if /i "%attr%" EQU "printLanguage" set lng=%data%&goto :EOF
if /i "%attr%" EQU "printMaxResolutionSupported" set res=%data%&goto :EOF
if /i "%attr%" EQU "printBinNames" call :setmult bins&goto :EOF
if /i "%attr%" EQU "printOrientationsSupported" call :setmult orient&goto :EOF
if /i "%attr%" EQU "printMediaReady" call :setmult paper
goto :EOF
:setmult
call set work=%%%1%%
if "%work%" NEQ "" set work=%work%;
set %1=%work%%data%
goto :EOF
:output
@echo "%share%","%name%","%loc%","%desc%","%srv%","%ppm%","%res%","%orient%","%color%","%paper%","%bins%","%dpx%","%stp%","%coll%","%lng%">>%csvfile%
set share=%data:~1%
set loc=
set desc=
set srv=
set ppm=
set res=
set orient=
set bins=
set color=
set paper=
set dpx=
set stp=
set coll=
set lng=



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