Remove all network printers from a workstation

The script allows you to delete all network printers on a workstation / server.

'
'    RDR REMOVE NETWORK PRINTER
'
'
'
Dim strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")
Set WshNetwork = WScript.CreateObject("WScript.Network")
'msgbox "open script"
' Boucle sur les imprimantes
For Each objPrinter in colInstalledPrinters
  'msgbox objPrinter.Name
    
  ' On verifie que l on est bien sur un imprimante reseau
  if lcase(Left(objPrinter.Name,3)) = "\\1" then
    'msgbox objPrinter.Name
    ' On supprime l imprimante
    WshNetwork.RemovePrinterConnection objPrinter.Name, true, true
  end if 
Next

Adaptation of the script

Delete all printers :

On line 17

Search : lcase(Left(objPrinter.Name,3)) = “\\1”

Replace by : lcase(Left(objPrinter.Name,2)) = “\\”

Remove mapped printers from a specific server :

À la ligne 17

Search : lcase(Left(objPrinter.Name,3)) = “\\1”

Replace by : lcase(Left(objPrinter.Name,9)) = “\\srv-imp”

9 : matches the number of characters in \\srv-imp

Romain Drouche

Romain Drouche

Architecte Système | MCSE: Core Infrastructure

Expert en infrastructures IT avec plus de 15 ans d'expérience sur le terrain. Actuellement Chef de projet Systèmes et Réseaux et Référent SSI (Sécurité des Systèmes d'Information), je mets mon expertise au service de la fiabilité et de la sécurité des environnements technologiques.

GHinM▶