Remove Printer - PowerShell


Overview

Remove-Printer is a PowerShell command that removes a specified printer from the list of available printers on a computer running Windows. It is commonly used to remove obsolete or unwanted printers, or to manage printer installations on multiple computers.

Syntax

Remove-Printer [-Name] <String> [-Server] <String> [-ComputerName] <String> [-Port] <String> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

Options/Flags

  • -Name: Specifies the name of the printer to be removed. This is the name of the printer as it appears in the Printers control panel.
  • -Server: Specifies the name of the computer hosting the printer to be removed. This is only required if the printer is not installed on the local computer.
  • -ComputerName: Specifies the name of the computer from which to remove the printer. This is only required if the printer is being removed from a remote computer.
  • -Port: Specifies the port to which the printer is connected. This is only required if the printer is connected to a specific port.
  • -Force: Forces the removal of the printer, even if it is currently being used.
  • -WhatIf: Shows what would happen if the command were run without actually making any changes.
  • -Confirm: Prompts for confirmation before removing the printer.

Examples

Example 1: Remove a printer from the local computer by name

Remove-Printer -Name "HP LaserJet 1018"

Example 2: Remove a printer from a remote computer

Remove-Printer -Server "RemoteComputer" -Name "HP LaserJet 1018"

Example 3: Remove a printer that is currently being used

Remove-Printer -Name "HP LaserJet 1018" -Force

Common Issues

  • Permission denied: The user does not have sufficient permissions to remove the printer. Ensure that the user has administrative privileges.
  • Printer is not installed: The printer is not installed on the specified computer. Verify that the printer is properly installed.
  • Incorrect printer name: The printer name is incorrect. Check the Printers control panel to ensure that the name is correct.

Integration

The Remove-Printer command can be used in conjunction with other PowerShell commands to automate printer management tasks. For example, the following script removes all printers from a specified server:

$printers = Get-Printer -Server "Server1"
foreach ($printer in $printers) {
  Remove-Printer -Server "Server1" -Name $printer.Name
}
  • Get-Printer: Retrieves information about printers installed on a computer.
  • Set-Printer: Modifies the properties of an installed printer.
  • Add-Printer: Adds a new printer to the list of available printers on a computer.