Recently, I had a project to move about 70 printers from one domain member server to another. This was a very easy task, but I had a problem when I had to migrate the network printers on users computers. We don’t use login scripts or group policy to map the printers, so first thought was to visit each user and remap the network printers. But we have about 350+ users and visiting each one was out of the question. I was looking to script this problem and I found a couple of links (see below), that helped me to wrote my own script. After I tested it, we used MS SMS to push this script to every user. Still, there were some minor issues, but we fixed them manually.
This VBscript is very straightforward and it is well commented, so it is very easy to understand.
Click below to download…
'===================================================================== ' ' ' Program: AddRemPrt.vbs ' Version: 2.0 ' Author: Kliment Andreev ' Date: 08/22/2008 ' ' Comment: This VBScript will list all network printers in a file ' on \\LogShare\UserName+ComputerName.txt, then it will add the same printers ' from a new print server and delete the old ones ' ' Note: 1. Printers defined on the new server must be with the same name ' or some suffix plus the same name ' 2. Printers must exist on the new server ' e.g \\OldServer\PrinterName must exists ' as \\NewServer\PrinterName or as \\NewServer\Prefix+PrinterName ' 3. Make sure \\LogShare is accessible by everyone for writing ' 4. This script won't install network printers that are installed as local using TCP port ' ' Copyright: Public Domain ' ' '===================================================================== Option Explicit dim strOldServer ' Old printserver name, defined below dim strNewServer ' New printserver name, defined below dim strLogShare ' Full path to a share where log files will be created dim strOldPrinterPath ' Full path (\\servername\printername) of the old printer dim strNewPrinterPath ' Full path (\\servername\printername) of the new printer + prefix dim strPrinterName ' Name of the printer only dim strComputerName ' String that contains the computername dim strUserName ' String that contains the username dim strPrefix ' Prefix that will be added to the new printer name dim objFSO ' Object to work with Files dim objNetwork ' Object to work with Network Printers dim objShell ' Object to work with ENV variables dim objFile ' Full path of the file that contains the printers dim objOldPrinters ' Object that contains all printers (including local) dim i, strTemp ' Helper varaibles Set objFSO = CreateObject ("Scripting.FileSystemObject") Set objNetwork = CreateObject ("Wscript.Network") Set objShell = CreateObject ("WScript.Shell") strOldServer = "USLCPDMGT02" strNewServer = "USCORPRINTSRV01" strLogShare = "\\USCPDITCR01\PrtLogs" strPrefix = "CPD_CR_" strComputerName = objShell.ExpandEnvironmentStrings("%ComputerName%") strUserName = objShell.ExpandEnvironmentStrings("%UserName%") Set objFile = objFSO.CreateTextFile (strLogShare & "\" & strUsername & " - " & strComputerName & ".txt") Set objOldPrinters = objNetwork.EnumPrinterConnections For i = 0 to objOldPrinters.Count - 1 strTemp = UCase(mid(objOldPrinters.Item(i), 1, 2 + len(strOldServer))) If strTemp = "\\" & strOldServer Then strOldPrinterPath = objOldPrinters.Item(i) strPrinterName = mid(strOldPrinterPath, 3 + 1 + len(strOldServer)) objFile.Write(strOldPrinterPath & vbCrLf) ' Write \\server\printer to a file strNewPrinterPath = "\\" & strNewServer & "\" & strPrefix & strPrinterName objNetwork.AddWindowsPrinterConnection strNewPrinterPath ' Add new printer objNetwork.RemovePrinterConnection strOldPrinterPath, True, True ' Remove the old one End If Next objFile.Close