Solved

delete printers from command line using wildcards

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
USB Error 20 170
Inkjet vs. Deskjet 5 27
1350 HP printer error - paper jam 8 34
NFS Improper UID & NFS Exported Share Read Access 7 70
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…
This seems to be a very common error related to the Samsung printer driver. First, this is the error we're talking about: Log: System Type: Error Event: 7000 Agent Time: 3:37:24 am 22-Apr-09 Event Time: 6:07:24 pm 21-Apr-09 UTC Source: Se…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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