Question : Find all the printers installed on all the machines in the file

Hi,

I need to find all the printers installed in a remote machine.All the machine names are in a file.The default printer has to be mentioned in the results.

Regards
Sharath

Answer : Find all the printers installed on all the machines in the file

:: ===============
:: READ THIS FIRST
:: ===============
:: * This script require "Computers.txt" file on C: drive root from where it will read computer names.
:: * Successful run will generate "PrintersReport.txt" file on C: drive root
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.

:: *** SCRIPT START ***
@Echo Off
SetLocal EnableDelayedExpansion

IF NOT EXIST C:\Computers.txt Goto ShowErr
FOR %%R IN (C:\Computers.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\PrintersReport.txt DEL /F /Q C:\PrintersReport.txt

FOR /F "delims=*" %%c IN ('Type C:\Computers.txt') Do (
      Echo Processing: %%c
      Echo ------------------------------------->>C:\PrintersReport.txt
      Echo Printers installed on %%c: >>C:\PrintersReport.txt
      Echo ------------------------------------->>C:\PrintersReport.txt
      SET Qry=WMIC /Node:"%%c" Printer WHERE "Default=True" GET NAME /Value ^| FIND /I "Name="
      FOR /F "Delims== Tokens=2" %%p IN ('!Qry!') Do (SET DPrinter=%%p)
      SET Qry=WMIC /Node:"%%c" Printer GET NAME /Value ^| FIND /I "Name="
      FOR /F "Delims== Tokens=2" %%p IN ('!Qry!') Do (
            IF "!DPrinter!"=="%%p" (
                  Echo %%p ^(Default^)>>C:\PrintersReport.txt) ELSE (
                  Echo %%p >>C:\PrintersReport.txt)
      )
)
Goto EndScript
:ShowErr
Echo "C:\Computers.txt" file does not exist or file is empty!
:EndScript
ENDLOCAL
:: Batch Script End
Random Solutions  
 
programming4us programming4us