Windows Enterprise Desktop

May 29 2019   1:20PM GMT

PowerShell Clears Stale Printer Objects

Ed Tittel Ed Tittel Profile: Ed Tittel

Tags:
Network printers
Printer management
Windows 10

I’ve got a somewhat temperamental driver for my otherwise excellent Samsung ML-2850 network printer. Every now and then, the driver goes sideways for no obvious reasons. When that happens, I simply use Devices & Printers to remove the device, and then use its TCP/IP address to reinstall it. This works just fine, but it tends to leave various stale printer objects around. So now, I’ve learned that PowerShell clears stale printer objects away. This lets me spruce things up after I go through the “remove printer — reinstall printer” dance with relative ease. Here’s what things looked like in PowerShell this morning, when I used the Get-Printer cmdlet (in table format) to see what was what:

PowerShell Clears Stale Printer Objects.duplicates

Notice that table rows 3-5 are all for the same printer: a Samsung ML-2850 device.
[Click image for full-sized view.]

How PowerShell Clears Stale Printer Objects

As a somewhat mangled PowerShell version of the old saw goes: “There’s a cmdlet for that!” The name of that cmdlet is Remove-Printer, and it’s part of the family of PowerShell cmdlets known as PrintManagement. I will observe that the whole family is worth getting to know for general printer and related port, job, and driver handling, even though I’ll focus here on Remove-Printer and Get-Printer exclusively.

The simple syntax for using Remove-Printer is to use its -name parameter. Because I’ve decided to remove all of my Samsung printers and create a new entry, the removal is dead simple. (I’ll use Add a Printer in Devices & Printers to add a new entry after removing the ones shown above. I’ll name it “SamsNWP2850” to put maker, type [NetWorked Printer, or NWP], and model number in that name.])

Here’s the syntax:
Remove-Printer -name "Samsung*"
That’s it. Pretty simple and straightforward, eh?

After a New Device Is Incarnated

Remember, I named that reincarnated Samsung ML-2850 printer as “SamsNWP2850.” By no coincidence whatsoever, it shows up at the first entry in the table format output from Get-Printer:

PowerShell Clears Stale Printer Objects.noduplicates

Now that the duplicates are gone, you can easily see the entire list of current printer definitions. Most of them I never use (Snagit, OneNote, Nitro PDF, XPS doc writer and fax).
[Click image for full-sized view.]

This kind of clean-up is worth conducting any time printer definitions get updated or replaced. OTOH, you could make it a semi-annual or yearly checkbox item, and perform clean-ups only when needed.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: