Remove a printer

In our Microsoft Office 365 v2016 C2R deployment , we have to delete the local “Send To OneNote 2013” printer. This printer was created when we installed Office 2013. After a little bit of searching, I found out 3 ways to delete a printer.

  1. Using command line

You can use the command to remove a printer.

Local printer:
rundll32 printui.dll,PrintUIEntry /dl /n “printer-name” /q

Network printer:
rundll32 printui.dll,PrintUIEntry /dn /n “printer-name” /q

Note:
/dl: delete local printer
/n: printer name
/q: quiet

To see all the options, run this command:
rundll32 printui.dll,PrintUIEntry /?

2. Using vbscript

This script scans all local printers on the system then remove the “Fax” printer. Modify the wmi query to get the network or all printers if needed.

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colInstalledPrinters = objWMIService.ExecQuery(“Select * from Win32_Printer where Network = FALSE”)
For Each objPrinter in colInstalledPrinters
 If StrComp(Trim(objPrinter.Name), “Fax”) = 0 Then 
  objPrinter.Delete_
 End If
Next

3. Using PowerShell

This script removes the network printers only. Modify the if statement to remove local or all printers if needed.

$printers = Get-WmiObject -Class win32_printer
foreach ($printer in $printers)
{
#Remove only network printers
if($printer.Name -ne $null -and $printer.Name.StartsWith(“\\”))
{
$printer.Delete()
}
}

Comments 2

Leave a Reply

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