The below script is an example of how you can migrate users from one printer server to another based on the printer model or name.
Sometimes doing a big bang migratiion 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 logn 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 users connection from one server to another.
The script will also preserve the users default printer.
If you would prefer a big bang approach take a look at this script .
This script could be easily changed to lookup from a list of share names rather than a list of drivers, please comment if you would like help with that
Set 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
ForEach 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 = TRUEthen
SetDefaultPrinter currentShareName
Endif
endif
Next
Endif
Sub MigratePrinter(OldPrinter, NewPrinter)
objNetwork.RemovePrinterConnection OldPrinter ' Remove from old
objNetwork.AddWindowsPrinterConnection NewPrinter 'Add on new
Endsub
Sub SetDefaultPrinter(ShareName)
Set colDefaultPrinter = objWMIService.ExecQuery ("Select * from Win32_Printer Where ServerName = "& printServerNew & " and ShareName = "& ShareName & "")
ForEach objDefaultPrinter in colDefaultPrinter
objDefaultPrinter.SetDefaultPrinter()
Next
Endsub
Attachment | Size |
---|---|
![]() | 2.17 KB |