Solved

Script to move computers from one print server to new print server

Posted on 2015-02-15
17
116 Views
Last Modified: 2015-03-25
Hi,
Looking for a script to move computers from one print server to another print server (Both Windows Servers, moving from x86 to x64 architect). the script should move the queue for users to new server as well.
the printers are located on 3 different floors, on each floor there are around 30 users.
thanks.
0
Comment
Question by:Leo
  • 8
  • 7
17 Comments
 
LVL 27

Expert Comment

by:serialband
ID: 40611654
Wouldn't it have been easier to do with group policy?  Do you have AD?

Someone has a powershell script to do that.
http://learn-powershell.net/2012/11/15/use-powershell-logon-script-to-update-printer-mappings/
0
 
LVL 8

Author Comment

by:Leo
ID: 40613222
We have AD, but this script needs to be run as a logon script, and only few floors are getting migrated to new printer, so if i run that script it will map all the users to new printer, correct me if i am wrong?
We dont have individual Group policy for each floor, the printers are added through logon script, so i am after a script which can be used as a logon script to map to new server and delete the old printer...
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 500 total points
ID: 40627866
Hi, I've used the script linked to in this thread to migrate printers from one server to another. It involves mapping your printers in an old share to new share manner, and so only changes print queues that are mentioned in the list.
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/Q_27093481.html

Regards,
Rob.
0
 
LVL 8

Author Comment

by:Leo
ID: 40634808
Hi, just few questions on the script that you suggested can be used....
strLogFileShare = "\\FileServer\userlogins$\PRINTSVR1_printer_changes\"
"userlogins$" whats this for?

  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
What does this command do?

"\\PRINTSVR1\CroydonCivic_LocalLaws1:\\PRINTSVR2\CroydonCivic_NeighborhoodServices1", _
      "\\PRINTSVR1\By_Laws_2300LH:\\PRINTSVR2\CroydonCivic_NeighborhoodServices1", _
      "\\PRINTSVR1\By_Laws_2300:\\PRINTSVR2\CroydonCivic_NeighborhoodServices1", _

This means its moving few different printers to new server, right? in my case printers are mapped at logon script, and each floor have its own printer, so I will be just using one array....right?

'MsgBox "Done" Where does this message gets send?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40634821
Hi, the userlogins$ part is just the share name of a shared folder on \\FileServer\
PrintSVR1_printer_changes is another folder inside that shared folder.

The impersonationLevel is a WMI moniker.  WMI is used to connect to the machine to query the attached printers.

You can use one array for the entire script.  Basically what it does is enumerates all of the network printers that a user has connected when they log on, and if a match is found on the left side of the colons, that printer will be replaced by the printer on the right side of the colon.

I am concerned though, that the print queues to be replace are *still* being mapped at logon, this will need to run *after* that script.

Rob.
0
 
LVL 8

Author Comment

by:Leo
ID: 40634855
"\\FileServer\userlogins$\PRINTSVR1_printer_changes\" so its just a share name for the printer?
With the Array, do i have to define for each floor which printer they are attached to? means...
      "\\OldServer\Floor13:\\NewServer\Floor13", _
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 40635022
Hi, I will try to explain it a bit better for you to understand how it works.

This line:
strLogFileShare = "\\FileServer\userlogins$\PRINTSVR1_printer_changes\"

points to a folder on a server share (public share), that every user needs to have write access to, In that folder, a file is created called <username>.txt, which is used purely for logging purposes, for you to check which user has had which printers remapped.

The Set objWMIService line initiates a WMI connection, and the Set colPrinters = objWMIService.ExecQuery line makes a WMI call to query the Win32_Printer class to retrieve any currently mapped printer (for the logged on user) that is NOT a local printer, ie, it is a network mapped printer.

The array in the middle of that is where the main configuration needs to take place.  You will see that each line in the array contains a colon.  On the left side of this colon is where you would type the queue name of the printer that is being replaced, and you don't want users to print to anymore.  On the right side of the colon is where you would type the queue name of the printer that is replacing the first one.  The two queue names can be completely different, the script simply removes the connection for the first, and replaces it with a connection to the second.

You can enter all of the old printers you are replacing, and all of the corresponding new printers.  Any printer that a user has mapped, that is NOT listed in the first element of each line, will not be touched.  That printer will still remain mapped for every user that already has it.

If you want to test it with just one printer, set the array to
arrPrinterShares = Array( _
      "\\PRINTSVR1\OldPrintQueue1:\\PRINTSVR2\NewPrintQueue1" _
)

and then keep an eye on the logging folder (set by strLogFileShare) to see what it is doing with users printers.

Hopefully that answers any questions you have.

Regards,

Rob.
0
 
LVL 8

Author Comment

by:Leo
ID: 40637624
Thanks.
kindly see the attached script, if i am doing it for one floor, one printer...would this be ok?
and i will be only making changes in the PrintSvr name....right?
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 8

Author Comment

by:Leo
ID: 40637625
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40637844
Correct, so what you have is:
strLogFileShare = "\\FileServer\userlogins$\PRINTSVR1_printer_changes\"

so that when a user logs on and a printer listed in arrPrinterShares is found, the change will be logged to that share.

You also have this:
arrPrinterShares = Array( _
      "\\PRINTSVR1\OldPrintQueue1:\\PRINTSVR2\NewPrintQueue1" _
)

so for any user (no matter what their location is, as long as they are running the script) that has \\PRINTSVR1\OldPrintQueue1 mapped, will have that removed, and replaced with \\PRINTSVR2\NewPrintQueue1, and it will be logged as above.

Remember that any user that is not connected to that printer, will not have their connected printers modified in any way.  Only the listed printers will be changed.

Regards,

Rob.
0
 
LVL 8

Author Comment

by:Leo
ID: 40638051
ok, so the script will automatically create this folder "userlogins$" if they dont have it already?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40638439
No. The shared folder that you specify on that line must exist, and be writable to all users.
0
 
LVL 8

Author Comment

by:Leo
ID: 40638924
Thanks, is there any folder in windows which is writable for all users?
because at my current workplace they dont have anything specific setup like that.......
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40638937
It's just a shared folder, so if you don't have a server that you can share a folder on to all users, then you should be able to select a client (eg your computer), and create a shared folder.  Otherwise, change the line to
strLogFileShare = "C:\Users\Public\Documents\"

but you will need to visit each PC to be able to know whether changes were made.

Rob.
0
 
LVL 8

Author Comment

by:Leo
ID: 40639015
ok, that will be a long procedure :-(
can this folder can be created on the server and i can give all staff full access to it, and when the script runs it logs the information based on there computer name into that folder?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40639067
Yes. Create a shared folder with Write access for Domain Users, and point that line yo that shared folder.  As a test for yourself, manually connect yourself to the shared printer you are replacing, then run the script to make sure it works.

Rob.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
I was supporting a handful of Windows 2008 (non-R2) 2 node clusters with shared quorum disks. Some had SQL 2008 installed and some were just a vendor application that we supported. For the purposes of this article it doesn’t really matter which so w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now