Here's a WIP of mine at the minute, a bit buggy at the minute, has a
tendency to delete the wrong printer :)
Not the tidiest, written in about 20 minutes and hasn't been looked at in
a couple of months so never went live.
IF I ever get round to finishing it, it'll run as part of the login
script.
Usual disclaimer, use at own risk :)
The script is supposed to do 2 things:
1. rename the server to an alias if it isn't already using it
2. rename the queue if it's an old one
The 6 queues in this script were replaced over time by 1 physical printer,
we have about another 5 physical printers on top of this with at least 4
redundant queues each.
The first part of the printersX line is the current old name, the second
is the new one to map it to.
8<--------------------------------------------------------------
Dim printersX(5)
printersX(0) = "NewBus_2870_096;Cvn_QFS_1stRight_VP2050"
printersX(1) = "Oce_CustCare_3511_234;Cvn_QFS_1stRight_VP2050"
printersX(2) = "HP LaserJet 4100 Series Renewals;Cvn_QFS_1stRight_VP2050"
printersX(3) = "Accounts_4100_55;Cvn_QFS_1stRight_VP2050"
printersX(4) = "CustCare_4050_022;Cvn_QFS_1stRight_VP2050"
printersX(5) = "Finance_Canon_123.232;Cvn_QFS_1stRight_VP2050"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from
Win32_Printer")
For Each objPrinter in colInstalledPrinters
If Left(objprinter.name,2)="\\" Then
myarray = Split(objprinter.name,"\",4)
myarray(2) = LCase(myarray(2))
If myarray(2) = "server_alias" Or myarray(2) =
"printserver1" Or myarray(2) = "printserver2" Then
For Each print1 In printersX
strprint = Split(print1,";",2)
'If LCase(myarray(2)) <> "server_alias"
Then
' myarray(2) = "server_alias"
'End If
If strprint(0) = myarray(3) Then
WScript.Echo "'" & strprint(0) &
"' has been replaced by '" & strprint(1) & "'"
'Set objNetwork =
WScript.CreateObject("WScript.Network")
'objNetwork.RemovePrinterConnection
objPrinter.Name
'WScript.Echo "Adding printer : " &
strprint(1)
'objnetwork.AddWindowsPrinterConnection
"\\server_alias\" & strprint(1)
'Set objNetwork = Nothing
'If objPrinter.Default = "True" Then
' Set colInstalledPrinters2 =
objWMIService.ExecQuery("Select * from Win32_Printer Where Name ='" &
strprint(1) & "'")
' For Each objprinter2 In
colInstalledPrinters2
' objPrinter2.setdefaultPrinter()
' Next
'End If
ReconnectPrinters objPrinter.name,
"\\server_alias", strprint(1)
Exit For
ElseIf myarray(2) <> "server_alias" Then
ReconnectPrinters objPrinter.Name,
"\\server_alias", myarray(3)
Exit For
End If
Next
End If
End If
Next
Sub ReconnectPrinters(strOldPrinter, strServer, strPrinter)
WScript.Echo "Deleting printer : " & strOldPrinter
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection strOldPrinter
WScript.Echo "Adding printer : " & strprinter
objnetwork.AddWindowsPrinterConnection strserver & "\" & strprinter
Set objNetwork = Nothing
If objPrinter.Default = "True" Then
Set colInstalledPrinters2 = objWMIService.ExecQuery("Select * from
Win32_Printer Where Name ='" & strprinter & "'")
For Each objprinter2 In colInstalledPrinters2
objPrinter2.setdefaultPrinter()
Next
End If
End Sub
8<--------------------------------------------------------------
Regards
Tony Patton
Desktop Operations Cavan
Ext 8078
Direct Dial 049 435 2878
email: [email protected]
From:
Gavin Wilby <[email protected]>
To:
"NT System Admin Issues" <[email protected]>
Date:
21/04/2010 14:21
Subject:
Printer managment
Hi All,
I have taken over yet another site of around 50 users, all on XP
workstations. They have a 2003 server that acts as a DC, and file and
print server.
They have around 20 odd network printers scattered over 4 floors, that
have all sorts of names and network addresses.
I want to rename them logically and give them all static addresses in
order of their name, so Laser 1 would be 192.168.100.201 for example.
Normally we would just rename the printer, change the IP address of it and
then manually remove the old queue from the relavant PC's and reattch the
new queue by connecting to \\server\laser1.
I feel there must be a better and less disruptive way of doing this,...
what do you guys do when managing large organisations?
--
Gavin Wilby,
Twitter: http://twitter.com/gavin_wilby
GSXR Blog: http://www.stoof.co.uk
This e-mail is intended only for the addressee named above. The contents should
not be copied nor disclosed to any other person. Any views or opinions
expressed are solely those of the sender and do not necessarily represent those
of QUINN-Insurance Limited (Under Administration), unless otherwise
specifically stated . As internet communications are not secure,
QUINN-Insurance Limited (Under Administration) is not responsible for the
contents of this message nor
responsible for any change made to this message after it was sent by the
original sender. Although virus scanning is used on all inbound and outbound
e-mail, we advise you to carry out your own virus check before opening any
attachment. We cannot accept liability for any damage sustained as a result of
any software viruses.
====================================================================
QUINN-Insurance Limited (Under Administration) is regulated by the Financial
Regulator and
regulated by the Financial Services Authority for the conduct of UK
business.
====================================================================
QUINN-Insurance Limited (Under Administration) is registered in Ireland,
registration number
240768 and is a private company limited by shares.
Its head office is at Dublin Road, Cavan, Co. Cavan.
This message is for the designated recipient only and may contain privileged,
proprietary, or otherwise private information. If you have received it in
error, please notify the sender immediately and delete the original. Any other
use of the email by you is prohibited.
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~