JSI Tip 5202. How do I retrieve the list of printers available on a print server, using a command?

Jerold Schulman

April 21, 2002

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


In tip 1407, I described the Net View command.

If I type net view \JSI001, it displays:

HP2250       Print                 HP Business Inkjet 2250 PCL 5CHP2250T1     Print                 HP Business Inkjet 2250 Top TrayHPOJRx80i    Print                 HP Office Jet Rx80i...          ...                   ...NETLOGN      Disk                  Logon server shareSYSVOL       Disk                  Logon Server Share...          ...                   ......          ...                   ...The command completed successfully.

If you have a many shares, it is difficult to find the printers.

I have scripted ShowPrinters.bat to display the printers only, or to allow you to further process the printer shares.

The syntax for using ShowPrinters.bat is:

ShowPrinters \PrintServer

The \ in front of the computer name of the print server is optional.

If I run ShowPrinters \JSI001, it returns:

\jsi001HP2250,HP Business Inkjet 2250 PCL 5C\jsi001HP2250T1,HP Business Inkjet 2250 Top Tray\jsi001HPOJRx80i,HP Office Jet Rx80i

If I wanted to process the list of printers in a batch file, I would script:

for /f "Tokens=1 Delims=," %%i in ('call ShowPrinters \JSI001') do call :MyLabel "%%i"

which would pass the following to MyLabel:

"\jsi001HP2250""\jsi001HP2250T1""\jsi001HPOJRx80i"

ShowPrinters.bat contains:

@echo offsetlocalif {%1}=={} goto syntaxset computer=%1set computer=%computer:"=%set computer=\%computer:=%for /f "Skip=7 Tokens=*" %%p in ('net view %computer%') do set entry=%%p&call :findprtendlocalgoto :EOF:syntax@echo Syntax: ShowPrinters \Serverendlocalgoto :EOF:stripset printer=%printer:"=%set printer=%printer:    ##=##%set printer=%printer:   ##=##%set printer=%printer:  ##=##%set printer=%printer: ##=##%goto :EOF:findprtif /i not "%entry:~13,5%" EQU "Print" goto :EOFset printer=%entry:~0,13%##set Comment=%entry:~35,99%:chkprinterset work=%printer: ##=##%if not "%work%" EQU "%printer%" call :strip "%printer%"&goto chkprinterset printer=%printer:##=%@echo %computer%%printer%,%comment%



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