Remove Printers Using Print Server Name

By | January 10, 2007

Two things keep me employed 1. Stupid People and 2. Printers!
Just after Christmas we had a server go down (This was our print server).
It cause all kinds of trouble reinstalling and such… but the biggest pain
were the printers (Their were so many of them). With all of the Terminal servers
using printer scripts and having users who cannot change their settings cause printers
to not be removed when the printserver is gone. To fix this issue I created this script
it will remove all printers from a specified "print server" (e.g., \\PSVR\colorlaser01).
This script can be run as a login script or added to an existing printer script.

———-COPY EVERYTHING BELOW THIS LINE———-

'This script will remove printer for the specified print server
'Created by Cheyenne Harden 1.10.07

On Error Resume Next

Dim arrPrinterName()
Dim strComputer, i, PrintServer
Dim objWMIService, objNetwork, colInstalledPrinters, objPrinter

strComputer = "."
i = 0
PrintServer = "PSVR" 'Your Print server name goes here!

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

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

 For Each objPrinter in colInstalledPrinters
 'This line is used for trouble shooting
    'Wscript.Echo "Name: " & objPrinter.Name
 
 ReDim Preserve arrPrinterName(i)
 arrPrinterName(i) = objPrinter.Name
  If InStr(arrPrinterName(i), PrintServer) Then
   Set objNetwork = WScript.CreateObject("WScript.Network")
   objNetwork.RemovePrinterConnection arrPrinterName(i)
   i=i+1
  
  Else
   'This line is used for trouble shooting.
   'WScript.Echo  "Name: " & objPrinter.Name
   
  End If

Next

———-COPY EVERYTHING ABOVE THIS LINE———-

 

PLEASE MAKE SURE NO WORD WRAPPING IS HAPPENING IN YOUR SCRIPT!!!

To make this script work you will need the items below!

1. Run this as a LogOn script.
2. Add the Print Server name here (PrintServer = "PSVR" 'Your Print server name goes here!) .
3. You will need the ability to remove printers.

This information is provided "AS IS" with no warranties expressed or implied.

Leave a Reply

Your email address will not be published. Required fields are marked *