This script will allow you to migrate user’s printer connections to a new server based on the printer model or the queue name. If you would prefer a big bang approach and migrate all printers based on the server’s name, look at this script.
Sometimes doing a big bang migration from an old print server to a new one is not the best idea, so this script allows you to provide a list of printer models to migrate rather than doing them all at once.
When I use this script, I call it from a logon script and add a model or two a day until the migration is complete.
The printers will need to be already setup, shared, and tested on your new server. This script will just move the user’s connection from one server to another.
The script will also preserve the users default printer.
This script could be easily changed to look up from a list of share names rather than a list of drivers, please comment if you would like help with that
on error resume nextSet objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer Where Local = False") Set objMigrationList = CreateObject("scripting.dictionary") Set objNetwork = CreateObject("WScript.Network") printServerOld = "\\PRINTSRV01" 'The server to move from MUST IN IN CAPS printServerNew = "\\PRINTSRV02" 'The server to move to MUST IN IN CAPS ' A list of models to migrate using the exact driver name as it appears in ' the Advanced tab of the printer MUST BE IN CAPS objMigrationList.Add "BROTHER HL-4040CN SERIES", "MIGRATE" objMigrationList.Add "BROTHER HL-5250DN SERIES", "MIGRATE" If colPrinters.Count <> 0 Then 'If there are some network printers For Each objPrinterInstalled In colPrinters ' For each network printer currentPrintServer = "" currentShareName = "" currentDriverName = "" currentIsDefault = False currentPrintServer = ucase(objPrinterInstalled.ServerName) ' Get the server name currentShareName = ucase(objPrinterInstalled.ShareName) ' Get the share name currentDriverName = ucase(objPrinterInstalled.DriverName) ' Get the driver name \ model currentIsDefault = objPrinterInstalled.Default ' If the current printer is connectd to the old server and if the driver is listed in ' objMigrationList then migrate the printer from the old server to the new if currentPrintServer = printServerOld and objMigrationList.exists(currentDriverName) then MigratePrinter currentPrintServer & "\" & currentShareName, printServerNew & "\" & currentShareName if currentIsDefault = TRUE then SetDefaultPrinter currentShareName End if end if Next End if Sub MigratePrinter(OldPrinter, NewPrinter) objNetwork.RemovePrinterConnection OldPrinter ' Remove from old objNetwork.AddWindowsPrinterConnection NewPrinter 'Add on new End sub Sub SetDefaultPrinter(ShareName) Set colDefaultPrinter = objWMIService.ExecQuery ("Select * from Win32_Printer Where ServerName = " & printServerNew & " and ShareName = " & ShareName & "") For Each objDefaultPrinter in colDefaultPrinter objDefaultPrinter.SetDefaultPrinter() Next End sub