This form does not yet contain any fields.
    Login
    « How cool is dnscmd? | Main | Be it known... »
    Friday
    Feb152008

    More for-do loop genius.

    "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)

    "Arsed" Is that an American word now?
    Your language young lady.
    March 6, 2008 | Unregistered CommenterMark

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    All HTML will be escaped. Hyperlinks will be created for URLs automatically.