Print Server Migration
We have been doing a migration from an older print server to a new one. I worked with the print server administrator to write a script that would make it easier to migrate workstations over to the new server. He had already duplicated the printer shares from the old server to the new one. We just needed a way to point the workstations to the new server. Here is what we wanted the script to do:
- read all network printers into an array
- read default printer into a variable
- delete all network printers that start with \\OldPrintServer
- add back all of the printers in the network printers array but use \\NewPrintServer as the servername
- If the original default printer was a network printer…set it back to that same name on the new server.
Here is what I came up with. There may be issues with line wrapping below. It is also available for download.
‘***********************************************************
‘***********************************************************
‘ Print Server Migration Script
‘
‘ Author: Jarvis Davis
‘ Company: Campus Crusade for Christ
‘ Creation Date: May 29, 2008
‘
‘ Purpose: To migrate workstations from one print server to another
‘ while maintaining the same printer names and default printer.
‘
‘ Assumption: This is assuming that you have already migrated the printer
‘ objects from one print server to another, and that the printer
‘ share names have stayed the same.
‘
‘***********************************************************
‘ General Flow:
‘ * read all network printers into an array
‘ * read default printer into a variable
‘ * delete all network printers that start with “\\OldPrintServer”
‘ * add back all of the printers in the network printers array but use \\NewPrintServer as the servername
‘ * If the original default printer was a network printer…set it back to that same name on the new server.
‘***********************************************************Set WshNetwork = CreateObject(“WScript.Network”)
strComputer = “.”
Set objWMIService = GetObject (“winmgmts:\\” & strComputer & “\root\cimv2”)‘ Read default printer into an array. Can be accessed using For Each objPrinter in colDefault
Set colDefault = objWMIService.ExecQuery (“Select * From Win32_Printer Where Default = TRUE”)‘ Read all printers from the old server into an array. Can be accessed using For Each objPrinter in colPrinters
Set colPrinters = objWMIService.ExecQuery (“Select * From Win32_Printer Where ServerName = ‘\\\\OldPrintServer'”)‘ Delete all network printers that start with OldPrintServer
For Each objPrinter in colPrinters
objPrinter.Delete_
Next‘ Add all network printers that were on the workstation using the new server name
For Each objPrinter In colPrinters
WshNetwork.AddWindowsPrinterConnection “\\NewPrintServer\” & objPrinter.Sharename
Next‘ Determine if the original Default Printer was a network printer. If so, set it using the new print server name
For Each objPrinter in colDefault
If objPrinter.ServerName = “\\OldPrintServer” Then
strOldPrinterName = objPrinter.ServerName
strNewPrinterName = Replace(strOldPrinterName, “OldPrintServer”, “NewPrintServer”)
objPrinter.SetDefaultPrinter(strNewPrinterName)
End if
Next
Wouldn’t it have been easier to just have the new server have the same name as the old? OK so it would have been a little difficult to parrallel test everything ahead of time as well, but just wondered.
I should have added though, that the script looks incredible and that you did a good job with it too. You even documented it well. You are a programmer in disquise Jarvis.
Doing an in-place upgrade might have been easier…but I wasn’t the one doing it. Jeff might be able to better tell why he didn’t choose to do it that way. I know one of the things that we are doing in this process is that the new server has up to date printer drivers on it that get installed when we remove and re-add the printers with the script. That in itself is fixing some issues.
Thanks for the compliments on the script. I still remember the HOSTS file modification script that you and I worked on. For a batch file, it had a lot of power…mostly provided by your one line…
type %SystemRoot%\system32\drivers\etc\hosts | find /i /v “oldserver” > %SystemRoot%\system32\drivers\etc\hosts.a
del %SystemRoot%\system32\drivers\etc\hosts
move %SystemRoot%\system32\drivers\etc\hosts.a %SystemRoot%\system32\drivers\etc\hosts
[…] https://verbalprocessor.com/2008/06/06/print-server-migration/ Published Saturday, June 07, 2008 5:08 PM by rodtrent Filed under: Scripting, Windows […]
Pingback by Print Server Migration – the script - Rod Trent at myITforum.com | June 7, 2008
thanks for this, this script was exactly what i was looking for, and good to find another blog from a Christian in IT
Thanks
Glad the script helped bud. I had looked everywhere (unsuccessfully) for a complete script that someone had already written and posted. Finally resorted to looking at the Scripting Guys site at Microsoft and used bits of their scripts as the jumping off points for mine.
Where do you work? (Use the contact form if you want to take the conversation off-line)
Hi Jarvis.
Great script. I’m testing on my network and I’m almost there.
The only issue is:
If you have older printer ports that do not exist on the new print server and home printers installed on the laptop, the script will fail. Do you know what can I add to the script to ignore all other printers other than the share ones on the two servers?
Thanks
Ben
Wish I had time to help you modify the script, but I’m barely keeping my head above water at work right now. As you’ve noticed, the script really was simply designed to migrate one for one.
although…we didn’t run into failures with home printers. The script should just ignore those except for setting that back to the default printer if a local printer was the default.