Need Help Scripting a User Mapped Printer Migration in Windows

Posted on 2012-03-20
Last Modified: 2012-03-28
I successfully migrated all printer queues, printers, drivers, ports, etc from one Windows 2008 SP2 server to another using the "Print Management" MMC. I have tested the newly migrated printers and they work fine.

My objective is not to mograte the printers from one server to another - but to migrate all my users' mapped network printers to the new print server.

I found the following script by Jeff Wouters:

I modified it to include my print servers and printers - as follows:

'Here comes a list with all printers identified by their old and new name.
'The first item is the old name and the second item is the new name.
Dim OldPrinterName(200)
Dim NewPrinterName(200)
dim objPrinter
OldPrinterName(0) = "\\printsrv01\HP Color LaserJet CM1312nfi MFP"
NewPrinterName(0) = "\\printsrv02\HP Color LaserJet CM1312nfi MFP"
OldPrinterName(1) = "\\printsrv01\HP Deskjet 6940 (Nicole's)"
NewPrinterName(1) = "\\printsrv02\HP Deskjet 6940 (Nicole's)"
OldPrinterName(2) = "\\printsrv01\HP Deskjet 6940 Diane"
NewPrinterName(2) = "\\printsrv02\HP Deskjet 6940 Diane"
OldPrinterName(3) = "\\printsrv01\HP LaserJet M1522nf"
NewPrinterName(3) = "\\printsrv02\HP LaserJet M1522nf"
OldPrinterName(4) = "\\printsrv01\HP LaserJet P2055dn PCL"
NewPrinterName(4) = "\\printsrv02\HP LaserJet P2055dn PCL"
OldPrinterName(5) = "\\printsrv01\HP LaserJet P3005 PCL6"
NewPrinterName(5) = "\\printsrv02\HP LaserJet P3005 PCL6"
OldPrinterName(6) = "\\printsrv01\KONICA MINOLTA C652SeriesFAX"
NewPrinterName(6) = "\\printsrv02\KONICA MINOLTA C652SeriesFAX"
OldPrinterName(7) = "\\printsrv01\KONICA MINOLTA C652SeriesPCL"
NewPrinterName(7) = "\\printsrv02\KONICA MINOLTA C652SeriesPCL"
OldPrinterName(8) = "\\printsrv01\KONICA MINOLTA C652SeriesPS"
NewPrinterName(8) = "\\printsrv02\KONICA MINOLTA C652SeriesPS"
OldPrinterName(9) = "\\printsrv01\KONICA MINOLTA C652SeriesXPS"
NewPrinterName(9) = "\\printsrv02\KONICA MINOLTA C652SeriesXPS"

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections
dim printerIndex
printerIndex = 0

'Walk through the printers
For each printer in printers

'Determine the default printer
Dim objShell
Dim sPath
Dim sPrinter
Dim sPort
Dim sDriver
Dim ar_PrnInfo
Dim defaultPrinterName
Set objShell = CreateObject("WScript.Shell")
sPath = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
ar_PrnInfo = Split(objShell.RegRead(sPath), ",")
If IsArray(ar_PrnInfo) Then
sPrinter = ar_PrnInfo(0)
sPort = ar_PrnInfo(2)
sDriver = ar_PrnInfo(1)
End If
defaultPrinterName = UCase(sPrinter)

'Walk through the list of printers that need to be changed
For each ReplacePrinter in OldPrinterName
if UCase(printer) = UCase(ReplacePrinter) then
if Len(ReplacePrinter) then
WshNetwork.RemovePrinterConnection ReplacePrinter
WshNetwork.AddWindowsPrinterConnection NewPrinterName(printerIndex)
'WScript.echo "WshNetwork.RemovePrinterConnection"  & ReplacePrinter
'WScript.echo "WshNetwork.AddWindowsPrinterConnection"  & NewPrinterName(printerIndex)
end if
printerIndex = printerIndex + 1
end if
'The following sleep is to avoid timeouts with drivers that take a lot of time to install
WScript.Sleep 1000

'Set the default printer
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers2 = WshNetwork.EnumPrinterConnections
Dim printerNameWithoutServer
Dim tempArray
Dim printerNameWithoutServerNew
Dim tempArrayNew

'Walk through all the printers
For each printer in printers2
If InStr(defaultPrinterName,"\") <> 0  Then
tempArray = Split(defaultPrinterName, "\")
printerNameWithoutServer = tempArray(UBound(tempArray))
printerNameWithoutServer = ""
End If
if InStr(printer,"\") <> 0 then
tempArrayNew = Split(printer,"\")
printerNameWithoutServerNew = tempArrayNew(UBound(tempArrayNew) )
printerNameWithoutServerNew = ""
end if
if (printerNameWithoutServerNew <> "") and (UCase(printerNameWithoutServer) = UCase(printerNameWithoutServerNew))Then
MsgBox "The network printers have been moved to a new server and printer " + (printerNameWithoutServer)+ " is still your default printer"
end if

Open in new window

I had to comment-out the following line:
...because it kept generating an "Object Required" error.
This is likely a cause for the script not completely working - though it at least runs without errors now.

The works thus far:
It correctly removes all printers that were mapped to the old print server.
It correctly counts the number of mapped network printers, and remembers that.
It maps the right _number_ of network printers to new print server.
...thats about it.

Where it fails:
It doesn't seem to remember the default printer.
It simply maps good network printers in order on the list - rather that the correct printers.
The 'printerIndex' is not incrementing, so it always adds printer(0).

I feel like I'm so close on this - just need another nudge in the right direction.
Thanks for your advice,
Question by:neilpage99
1 Comment

Accepted Solution

neilpage99 earned 0 total points
ID: 37779684
I wasn't asking for someone to write me a script - just point out where I went wrong with mine.

Nevermind, 8 days later no comments. I'll close it.
Seems to be the trend.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
Resolve DNS query failed errors for Exchange
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question