Remove Network Printers via WMI
Earlier this year I needed to migrate all of my users to a new print server. I essentially had two options for removing the old printers. Option one included visiting each workstation and removing the printers manually. The second option, which is the road that I chose was to script the removal of these old printers. I came up with this quick VB Script to accomplish this mundane task.
'Created by Dustin Berube on 3/22/2010 Version 2.0 'Documented on 3/22/2010 ' This script will loops through all installed ' network printers on a workstation and removes ' them. Recommend running this as a Logoff script. strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer Where Network = TRUE") For Each objPrinter in colInstalledPrinters objPrinter.Delete_ Next
In my case I ran the script through Group Policy as a log off script. The reasoning for that was at the end of the day I had all my users log off of their workstations (which triggered this script to remove all network printers from their workstations). The next time they logged onto their workstations the new printers were pushed through a different script to map the printers. This script utilizes WMI to query the local workstation and select all network printers from the Win32_Printer object. Once it retrieves a list of printers this script will loop through the printers and delete them one at a time.
As always, I have provided this script “AS-IS”.