Thanks to the experts here I have a script that will delete a network printer and replace it with another on a different server.
In my testing I discovered that some of my permissions are not same from one printer to the other (my problem).
Right now the script will see the old printer, delete it, and then fail to install the replacement. Which leaves the user without a printer. Bad news for me.
What I'd like to be able to do is add some additional logic in the script that will confirm the addition of the replacement printer prior to deleting the old one. Here is the script with one printer:
Dim objWMIService, objPrinter, colItems, strComputer, objWshShell, strDefaultState
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' For Remote:
' Set Locator = CreateObject("WbemScripting.SWbemLocator")
' Set objWMIService = Locator.ConnectServer(strComputer, "root\cimv2",
' strUserName, strPassword)
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
' On Error Resume Next
' ***Share name: printer1***
For Each objPrinter In colItems
If UCase(objPrinter.DeviceID) = UCase("\\server1\printer1") Then
'Wscript.Echo "Found match " & objPrinter.DeviceID & ", replacing"
' Add new printer. Need the ,1,true to wait for shell to complete before continue
objWshShell.Run "rundll32 printui.dll,PrintUIEntry /in /Gw /q /n ""\\server2\printer2"" ",1, True
' Remove the old
objWshShell.Run "rundll32 printui.dll,PrintUIEntry /dn /q /n ""\\server1\printer1"" ",1, True
If objPrinter.Default Then ' if it's the default set as default
objWshShell.Run "rundll32 printui.dll,PrintUIEntry /y /n ""\\server2\printer2"" ",1, True