Skip to content

Powershell – Remove old printer from Registry

Running into printers which should be deleted ages ago or causing all sorts of random issues like randomly appearing after deleting them, I think at some point we have all ran into that.
After a while I’ve found an article which guided me to a location in the registry where these guys were just hanging around, waiting to pop-up again. So I’ve created a script to deal with them.

First of all you do need PsExec (available on Microsoft Docs) since it is a SYSTEM protected location. Then execute Powershell ISE with the “PsExec.exe -s -i Powershell_ISE” command.

Then paste the following script and edit the ‘PrinterName’ variable;

$PrinterReg = Get-ChildItem -Path 'HKLM:\SYSTEM\CurrentControlSet\Enum\SWD\PRINTENUM\*'
$PrinterName = "\\SERVER\Printer Name"

Foreach ($DeletePrinter in $PrinterReg){

$FriendlyName = $DeletePrinter.GetValue("Friendlyname")

if($FriendlyName -eq $PrinterName){

Remove-Item -path $DeletePrinter.PSPath -Recurse
Write-Host "Removing $friendlyname from $($DeletePrinter.PSPath)"

}}

That should be it!

Published inPowerShellServer 2016Windows Server

2 Comments

  1. Žan Žan

    Thank you Aad!

    This is exactly what I was looking for!

  2. tanert tanert

    This did not worked for me. After relogin those registry keys were recreated.

    Printers can be found from many places in Registry. Eg.

    Tietokone\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\Client Side Rendering Print Provider\Servers\example-server-name\Printers

    HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers\Client Side Rendering Print Provider\Servers\example-server-name\Printers\

Leave a Reply

Your email address will not be published.