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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

An article on effective troubleshooting
Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

724 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