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
System Architect | MCSE: Core Infrastructure
IT infrastructure expert with over 15 years of field experience. Currently a Systems and Networks Project Manager and Information Systems Security (ISS) expert, I use my expertise to ensure the reliability and security of technological environments.

Leave a Comment