This is a script that I wrote to change the printers on client
computers from an old server to a new one.
It is somewhat messy, but I though someone might benefit from it. As
you can see in the code, we had special circumstances for 2 of our
printers. If you don't have problems like this, you could remove most
of the middle sections and just move the printers to the new server.
This does require that the printers are shared with the same name on
the new server. There are some message box pop ups that are commented
out, these just help with troubleshooting.
Please let me know if you appreciate this, or if you want me to shut
up. I have many more admin scripts like this that I could share.
********************************
moveprinters.vbs
********************************
'Mark Fergason
'10/13/06 - That's Right Friday the 13th
'This script puts all printers in an array, then it will
'rename them based on the printer name.
'Due to not having 2003 drivers for the sharp printer
'it must search for that and move it to a different server
'The xerox printer was setup on some pcs and is no longer
'available, therefore it is just deleted
'use find/replace for svr1, svr2, and svr3
'---------------------------------------------------------
'---------------------------------------------------------
'all of this sets the array numprint with all the printers on a
computer
'-------------------------------------------------------
On Error Resume Next
Dim WshNetwork, objPrinters, i, Count
Set WshNetwork = CreateObject("WScript.Network")
Set objPrinters = WshNetwork.EnumPrinterConnections
Count = objPrinters.Count
Dim numprint()
ReDim numprint(Count)
For i = 0 to objPrinters.Count - 1 Step 2
numprint(i)=objPrinters.Item(i+1)
Next
'this will determine if the printer is on svr1
'if the printer in numprint(2) is on svr1 isthere(2) will = 3
'--------------------------------------------------------
Dim isthere()
ReDim isthere(Count)
Dim issharp()
ReDim issharp(Count)
Dim isxerox()
ReDim isxerox(Count)
Dim ispcl()
ReDim ispcl(Count)
For i = 0 to objPrinters.Count - 1 Step 2
isthere(i)=InStr(1, numprint(i), "svr1", VBTextCompare)
If isthere(i)=3 Then
issharp(i)=InStr(1, numprint(i), "sharp", VBTextCompare)
If issharp(i)>3 Then
ispcl(i)=InStr(1, numprint(i), "pcl", VBTextCompare)
If ispcl(i)>5 Then
WshNetwork.RemovePrinterConnection numprint(i)
WshNetwork.AddWindowsPrinterConnection "\\svr3\Sharp AR-651-PCL6"
Else
WshNetwork.RemovePrinterConnection numprint(i)
WshNetwork.AddWindowsPrinterConnection "\\svr3\Sharp AR-651-PS3"
End If
Else
isxerox(i)=InStr(1, numprint(i), "xerox", VBTextCompare)
End If
End If
'MsgBox i & " " & numprint(i) & " " & isthere (i)
Next
'this will remove the printers that are connected to svr1
'unless sharp that has alredy been moved
'if it is the xerox, it will just delete it
'--------------------------------------------------------
For i = 0 to objPrinters.Count - 1 Step 2
If isthere(i)=3 Then
If isxerox(i)>2 Then
WshNetwork.RemovePrinterConnection numprint(i)
Else
If issharp(i)<3 Then
WshNetwork.RemovePrinterConnection numprint(i)
'MsgBox i & " " & numprint(i) & " " & isthere (i)
End If
End If
End If
Next
'this changes names from svr1 to svr2 to re-add the printers
'unless sharp because it would not install on svr2
'--------------------------------------------------------
Dim changeprint()
ReDim changeprint(Count)
For i = 0 to objPrinters.Count - 1 Step 2
If isthere(i)=3 Then
If issharp(i)<3 Then
tempprint=numprint(i)
changeprint(i)=Replace(tempprint, "svr1", "svr2")
WshNetwork.AddWindowsPrinterConnection changeprint(i)
'MsgBox i & " " & changeprint(i) & " " & isthere (i)
End If
End If
Next