Using PowerShell to Remove a Network Printer for All Users of a Computer

Purpose

This brief article details the commands necessary to use PowerShell to remove a network printer for all users of a computer.

Prerequisites

The below actions require the executing user to be an administrator of the remote workstation, or a Domain Administrator.

Solution

Establish a Remote PowerShell session

In an elevated PowerShell session (running as administrator), run the following command;

Enter-PsSession -ComputerName HOSTNAME.FQDN

where HOSTNAME.FQDN is the fully-qualified domain name of the workstation in question.

Example: desktop01.yourdomain.com

You can actually perform these commands without using the FQDN, and using the short name instead.

Remove the network printer for all users

Once you’ve entered the remote PowerShell session successfully, run the following commands in sequence;

Get-WmiObject -Class Win32_Printer | where{$_.Name -eq ‘\\PRINTSERVER\Shared-printer‘}

where PRINTSERVER is the NETBIOS name of your print server from which the printer is shared and Shared-printer is the shared name of the printer you’d like to remove. This command will return the printer that you’d like to remove, if it is installed for the user running the command. Even if the user running the command does not have this printer installed, this process will still work as intended.

Get-WmiObject -Class Win32_Printer | where{$_.Name -eq ‘\\PRINTSERVER\Shared-printer‘}| foreach{$_.delete()}

again, where PRINTSERVER is the NETBIOS name of your print server from which the printer is shared and Shared-printer is the shared name of the printer you’d like to remove.

When this is complete, the network printer should be uninstalled/removed for all users on that workstation. This can be verified by having users logon and check their Devices and Printers window.

Author: griffethbarker

Griff is a tinkerer and manager of IT, consultant of IT and management, and continuous student of organizational development. His hobbies and interests include games of all types (video, board, dice, card, tabletop, etc.) as well as listening to music, photography, and writing. Find him on LinkedIn!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s