Site icon RDR-IT

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

Exit mobile version