Jump to content

Recommended Posts

Posted

I have a very simple script to remove all network printers, however this does not remove old printers that are no longer attached to the network.

 

How should I modify the attached script to remove 'all' printers?

 

Go easy on me, scripts are not my forte :)

remove-network-printers.vbs.txt

Posted

I've used this in the past to remove network printers

 

'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

 

and this to remove local printers

 

'Remove all Local printers but not Network printers
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
   ("Select * from Win32_Printer Where Network = FALSE")

For Each objPrinter in colInstalledPrinters
   objPrinter.Delete_
Next

Posted

Thanks for the reply.

 

Whilst this does remove network printers, it does not seem to remove printers that are dead i.e status is "unable to connect"

 

Any other ideas?

Posted

sorry, I missed that, this will do it.

 

'Remove all offline printers
set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")

set sInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer where ExtendedPrinterStatus = 7")

For Each sPrinter in sInstalledPrinters
sPrinter.Delete_
Next

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...