Need Help Scripting a User Mapped Printer Migration in Windows

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,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

neilpage99Author Commented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.