More for-do loop genius.
Friday, February 15, 2008 at 03:45PM "We need to add 25 printers to each of 25 servers! The sky is falling!"
Create a text file as follows:
10.10.104.15, IP_10.10.104.15,"HP LaserJet 5000 Series PCL",SERVERA,"ServerA-HPLJ5000PCL"
To create the IP printer ports:
for /f "usebackq tokens=1,2,3,4,5 delims=," %a in (installprinters.txt) do cscript prnport.vbs -a -s %d -r %b -h %a >> err.txt
To add the printers once the ports are created:
for /f "usebackq tokens=1,2,3,4,5 delims=," %a in (installprinters.txt) do cscript prnmngr.vbs -a -p %e -m %c -r %b -s %d >> err.txt
A few random annoyances of this:
* Printer driver name must be precise, but you can grep this from the server hosting the printer using prnmngr.vbs with the -l switch
* If the printer driver isn't already installed on the target printer, the 2nd line will fail.
I'm sure there's a way to error-handle around that 2nd one, but I just can't be bothered this late on a Friday. I'll think about it more later if I'm in the mood. But then again, it's printers, so really I can't be arsed beyond this. :-)
Reader Comments (1)
Your language young lady.