Re-map all printers from one server to another

Script to migrate users from one server to another

Running the below will migrate all printer connections from "OLD-SERVER" to "NEW-SERVER" While keeping the original name of the printer.

 1strOldServer = "OLD-SERVER"
 2strNewServer = "NEW-SERVER"
 3
 4
 5strComputer = "."
 6Set WSHNetwork = CreateObject("WScript.Network")
 7Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" & strComputer & "\\root\\cimv2")
 8Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
 9
10strOldServer = prepServer(strOldServer)
11strNewServer = prepServer(strNewServer)
12
13For Each objPrinter in colInstalledPrinters
14strName = objPrinter.Name
15iPrinterLocation = InStr(UCase(objPrinter.Name),UCase(strOldServer))
16If iPrinterLocation > 0 then
17strPrinter = strNewServer & Right(strName, Len(strName) - Len(strOldServer))
18objPrinter.Delete_
19WSHNetwork.AddWindowsPrinterConnection strPrinter
20If objPrinter.Default = True Then
21WSHNetwork.SetDefaultPrinter strPrinter
22End If
23End If
24Next
25
26
27Function prepServer(strServer)
28If Left(strServer, 2) <> "\\\\" then
29strServer = "\\\\" & strServer
30End If
31If Right(strServer, 1) <> "\\" then
32strServer = strServer & "\\"
33End If
34prepServer = strServer
35End Function