Can I delete printers with certain status using a script?

By martin ·
I'm looking for a script to remove printers from users profiles with the status "Printer not found on server, unable to connect". These printers have been removed from the print server but I need to now run a script to remove them from the user profiles (in a logoff script). After much googling I've been able to find how to remove all printers and recreate those required but I really would like to know if it's possible to delete just those with this specific status.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

This might be useful

by Bizzo In reply to Can I delete printers wit ...

Below is a short script to display all printers in the profile:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
For Each objPrinter in colPrinters
WScript.echo objPrinter.Name
strPrinterState = objPrinter.PrinterState
WScript.echo strPrinterState

The main thing you're looking at here is the "PrinterState"
This page lists the possible values (1-25),
Then, depending on the current state, you can delete the printer using "RemovePrinterConnection", see

Related Discussions

Related Forums