script to delete all network printers

I am the worst at scripting. I am looking for a VB script that will allow users to delete all exisitng network printers so that we can assign new ones.
gedney77090Asked:
Who is Participating?
 
gedney77090Connect With a Mentor Author Commented:
Option Explicit
Dim objNetwork, strLocal, strUNCPrinter1, strUNCPrinter2
strUNCPrinter1 = "\\ptsvprt01\PTPR064"
strUNCPrinter2 = "\\ptsvprt01\PTPR067CP"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.AddWindowsPrinterConnection strUNCPrinter2
WScript.Quit


Here is the code that worked
0
 
Jared LukerCommented:
Hello gedney77090,

Here you go...

Good Luck,

Jared
----------------------------------------------------
'Remove all Network printers but not local printers
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections 
For i = 0 to Printers.Count - 1 Step 2 
    If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
        WScript.Echo Printers.Item(i+1)
        WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
    End IF
Next

Open in new window

0
 
gedney77090Author Commented:
I ran the script and windows popped up that said the printers would be deleted but they remained at the termination of the script.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RobSampsonCommented:
Are the printers connected directly to the print server from the client, or have you created the local TCP/IP ports to connect the printer to?

Regards,

Rob.
0
 
gedney77090Author Commented:
cleint to print server. I was able to create a script that worked. Thank you for your help.
0
 
RobSampsonCommented:
Oh that's great.  Was it similar to Jared's?  Would you mind sharing your code?

Rob.
0
All Courses

From novice to tech pro — start learning today.