Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

A script to install ip printer on a text file of computers.......Please advise and critique the following script for more efficiency....

$
0
0

 

Script is an amalgamation of Microsoft Printer utilities created in .VBS and PSEXEC
all wrapped inside a Powershell script.  I am looking for ways to streamline the scripts logic, and perhaps by adding functions for the printer ip address and maybe the text file.  Thanks.

Script begins below:

#:: Script for Installing IP Printers on computers that are pulled from a text file
#:: The variables that need to change are the IP Address (for the different printers)
#:: and the Department where the printer is in (which is added to the printer name on install)
#:: Modifed and customized by Phillip Trimble, COT, 7/24/2014 (last updated 2-2-15)
#:: Was used initially for converting queue printers at Thelma OVR over to IP printers.
 
# Variables for user name and password
 
$user='#$%#$%#%#$#$%'
$password='#$%#$%#$'
 
# Set IP address, office and printer name
 
$ipaddress = '10.65.18.59'
$office = 'calloway1.txt'
$printername = "Xerox WorkCentre 5945"
 
# Begin Looping through computers
 
cls 
write-host "Processing started..."
write-host 
 
 
 
    foreach ($computer in gc c:\batchfiles\ccpr\$office)
 
    {
 
    
    # Is computer $computer accessable?
 
    if (test-path -path "\\$computer\admin$")
 
        {
 
        write-host "$computer accessible" >>c:\batchfiles\ccpr\log\"success_log_"$office
 
        # REM Printer1
        # REM Deletes previously installed printer of the specified name
 
        #  Deleting previously installed printer 
 
        cscript "\\hfsro121-0581\e$\Deploy\prnmngr.vbs" -d -s $computer -p $printername
 
        # END Deleted Previously installed printer 
 
        # Deletes static port of previous printer, in case of mis-configuration
        # Deleting existing port
 
        cscript "\\hfsro121-0581\e$\Deploy\prnport.vbs" -d -s $computer -r IP_$ipaddress 
 
        # END Deleted IP port  
 
        # Creates TCP/IP port with specified IP address
        # Creating new port
        
        cscript "\\hfsro121-0581\e$\Deploy\prnport.vbs" -a -s $computer -r IP_$ipaddress -h $ipaddress -o raw -n 9100 
        
        # END Created IP Port 
 
        # Copies driver for printer from server to local directory
        # Copying drivers to remote machine
 
        # Have I already copied the printer drivers to this computer?  if so, not going to do it again!
                
        if (!(test-path -path "\\$computer\c$\printdrv\xunivxpl.ini"))
         
            {
        
            # Copying printer driver files to the remote computer
 
            psexec \\$computer -u $user -p $password xcopy /E /Y \\hfsro121-0581\e$\Deploy\Drivers\Xerox\GPD\*.* c:\printdrv\
                             
 
            }
                    
        
       cscript "\\hfsro121-0581\e$\Deploy\prndrvr.vbs" -a -s $computer -m "Xerox Global Print Driver PCL6" -e "Windows NT x86" -h "c:\printdrv" -i "c:\printdrv\x2UNIVX.inf" 
 
       cscript "\\hfsro121-0581\e$\deploy\prnmngr.vbs" -a -s $computer -p $printername -m "Xerox Global Print Driver PCL6" -r IP_$ipaddress
 
       cscript "\\hfsro121-0581\e$\Deploy\prnqctl.vbs" -e -s $computer -p $printername -u %user% -w %password%
 
       
    }
    
    else 
        {
        write-host "$computer not accessible" >>c:\batchfiles\ccpr\log\"error_log_"$office
        }
}
 
    
cls
write-host Processing complete for $office
# END


Viewing all articles
Browse latest Browse all 6937

Trending Articles