Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

delete printers from command line using wildcards

Posted on 2011-03-02
3
Medium Priority
?
1,406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Plug and play, no additional software required!

The ATEN UE3310 USB3.1 Gen1 Extender Cable allows users to extend the distance between the computer and USB devices up to 10 m (33 ft). The UE3310 is a high-quality, cost-effective solution for professional environments such as hospitals, factories and business facilities.

Question has a verified solution.

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

If you use a Brother DCP 130C or similar Brother printer, at some point you might encounter the following problem: after you change the ink cartridge, the printer displays an "ink empty" message. Sometimes you just need to follow the instructions…
When I recently replaced my image transfer kit on my office HP color laserjet 5550dn printer, I had a slight problem.  The left bracket that holds the transfer kit got stuck in the upright locked position instead of being at a 45 degree angle facing…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

647 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