Solved

delete printers from command line using wildcards

Posted on 2011-03-02
3
1,259 Views
Last Modified: 2012-08-13
I saw a solution in an older thread here:
http://www.experts-exchange.com/Hardware/Peripherals/Printers_Scanners/Q_23476195.html

Anyone know if you can use wildcards in those scripts? we are migrating a hundred or so workstations from one server to another, and need to delete all printers mapped to one server.  We will be using GPO deployed printers for the new ones.

So would something like this work?:


' Begin Code
Option Explicit
Dim objNetwork, strPrinter1
strPrinter1 = "\\server\*"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection strPrinter1

Wscript.Quit
0
Comment
Question by:cameramonkey
3 Comments
 
LVL 32

Expert Comment

by:Rodney Barnhardt
ID: 35028138
0
 

Author Comment

by:cameramonkey
ID: 35029419
I see lots of deleting ALL printers or ALL NETWORK printers, but none that support the wildcard of any printers on a specific server. I'm trying to avoid enumerating all 25 or so printers on that decommissioned server and deleting them individually since ALL printers on that server need to go without touching any others.
0
 
LVL 11

Accepted Solution

by:
yelbaglf earned 125 total points
ID: 35030700
Try something like this...

strComputer = "."
i = 0

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")

For Each objPrinter in colPrinters
	
	ReDim Preserve arrPrinterName(i)
	arrPrinterName(i) = objPrinter.Name
		If InStr(arrPrinterName(i), oldServer) Then
			objNetwork.RemovePrinterConnection arrPrinterName(i)
			i=i+1
		
		Else
			
		End If
	
Next

Open in new window

0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to solve seemingly unsolvable printer issues. Users sometimes run into printing issues where all the normal steps do not seem to work. Well the steps below can show users how to take one extra step beyond the normal steps needed to remove old…
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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