Solved

delete printers from command line using wildcards

Posted on 2011-03-02
3
1,213 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now