Link to home
Start Free TrialLog in
Avatar of Rich Smith
Rich SmithFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PowerShell to remove printers

I have just upgraded my old printer server from 2008r2 (TCPRINT01) to 2019 (TCPRINT02), I need to remove all the printers mapper to the old print server from my Windows 10 workstations, I have been trying to find a PowerShell script that can do this but I can only find a script that will remove all printers, can anyone help with a script that will only remove printers connected to TCPRINT01?

I was going to run the script at login unless anyone can recommend a different way to do this?

Avatar of DEMAN-BARCELO (MVP) Thierry
Flag of France image

Hi Rich,

you have many kind of script that are doing this migration from server/printer to another server/printer:

These scripts can  (simply) replace the old printer/server with a new printer during the logon of the user.

Here was my sample script :

The format file was "SourceServer,SourcePrinter,TargetServer,TargetPrinter" using NETBIOS names.
Only users that were connected to the old shares are modified.
Avatar of Rich Smith


Hi Thierry,

Thank you for the links, I don't have much experience with .vbs scripts, would these be run manually on each workstation or using a GPO to run at logon?

Thank you,
The script could be run for testing purpose in a connected user profile.

Connected printers are defined in HKCU (current user registry), so the administrator cannot change their configuration.

So, ideally, Yes, the script must be run in the logon script or in a GPO starting after the login of the user.
Avatar of oBdA

Here's a bit of PowerShell; it's in test mode and will not delete any connection; remove the -WhatIf at the end to run it for real:
$printServer = 'TCPRINT01'
Get-Printer | Where-Object {($_.Type -eq 'Connection') -and ($_.ComputerName -match "$($printServer)\b")} | Remove-Printer -Verbose -WhatIf

Open in new window

Hi oBdA,

I tried running the script and it only returns local printers and not the network printers, do I need to change the 'connection' ?

thank you, Rich
Then, sorry, but the only explanation I have is that you're not running the exact script I posted.
Local printers will have a type of "Local" and therefore will not pass the "($_.Type -eq 'Connection')" test, and neither will local printers have the property ComputerName set, so they won't pass "($_.ComputerName -match "$($printServer)\b")", either.
Demo run with some local printers (no network printers on this machine) that don't make it through the "Where-Object":
PS C:\> Get-Printer -Name 'Microsoft*' | select Name, Type, ComputerName

Name                           Type ComputerName
----                           ---- ------------
Microsoft XPS Document Writer Local
Microsoft Print to PDF        Local

PS C:\> Get-Printer -Name 'Microsoft*' | Where-Object {($_.Type -eq 'Connection')}
PS C:\>
PS C:\>

Open in new window

Avatar of DEMAN-BARCELO (MVP) Thierry
Flag of France image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial