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

Jerold Schulman

July 6, 2004

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

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

printShareNamePrinterNamelocationdescriptionshortServerNameprintPagesPerMinuteprintMaxResolutionSupportedprintOrientationsSupportedprintColorprintBinNamesprintDuplexSupportedprintMediaReadyprintStaplingSupportedprintCollateprintLanguage

The syntax for using ADPrinters.bat is:

ADPrinters CSVFileName

Where CSVFileName is the name of the CSV to generate.

ADPrinters.bat contains:

@echo offif {%1}=={} @echo Syntax: ADPrinters CSVFileName&goto :EOFsetlocalset csvfile=%1if exist %csvfile% del /q %csvfile%set qry1=dsquery * domainroot -filter "(&(objectClass=PrintQueue))" -attrset qry2= printShareName PrinterName location description shortServerName printPagesPerMinute printMaxResolutionSupportedset qry3= printOrientationsSupported printColor printBinNames printDuplexSupported printMediaReady printStaplingSupportedset qry4= printCollate printLanguage -L -limit 0set qry=%qry1%%qry2%%qry3%%qry4%set share=ShareNameset name=PrintNameset loc=Locationset desc=Descriptionset srv=Serverset ppm=PPMset res=DPIset orient=Orientationsset bins=Traysset color=Colorset paper=Paperset dpx=Duplexset stp=Stapleset coll=Collateset lng=Languagefor /f "Tokens=1* Delims=:" %%a in ('%qry%') do ( set attr=%%a set data=%%b call :build)call :outputendlocalgoto :EOF:buildif /i "%attr%" EQU "printShareName" call :outputset 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=Tif /i "%data%" EQU "FALSE" set data=Fif "%data%" EQU "" set data=if /i "%attr%" EQU "PrinterName" set name=%data%&goto :EOFif /i "%attr%" EQU "location" set loc=%data%&goto :EOFif /i "%attr%" EQU "description" set desc=%data%&goto :EOFif /i "%attr%" EQU "shortServerName" set srv=%data%&goto :EOFif /i "%attr%" EQU "printPagesPerMinute" set ppm=%data%&goto :EOFif /i "%attr%" EQU "printColor" set color=%data%&goto :EOFif /i "%attr%" EQU "printDuplexSupported" set dpx=%data%&goto :EOFif /i "%attr%" EQU "printStaplingSupported" set stp=%data%&goto :EOFif /i "%attr%" EQU "printCollate" set coll=%data%&goto :EOFif /i "%attr%" EQU "printLanguage" set lng=%data%&goto :EOFif /i "%attr%" EQU "printMaxResolutionSupported" set res=%data%&goto :EOFif /i "%attr%" EQU "printBinNames" call :setmult bins&goto :EOFif /i "%attr%" EQU "printOrientationsSupported" call :setmult orient&goto :EOFif /i "%attr%" EQU "printMediaReady" call :setmult papergoto :EOF:setmultcall 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=



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