How can I remove all legacy network printers with PowerShell?

0
0
Asked By VelvetOrchid42 On

I'm trying to remove all print-server-hosted printer connections from both computer and user contexts so Group Policy Preferences can manage the replacement queues. Some printers were deployed through older Group Policy printer deployment, while others use Group Policy Preferences.

Computer-context queues can be removed with commands such as `rundll32.exe printui.dll,PrintUIEntry /gd /n"\PRINTSERVERPRINTER"`, but user-context queues often return Access Denied because they must be removed within the affected user's profile. I'm looking for a reliable PowerShell or Group Policy approach that removes legacy network printer connections without requiring users to manually click Remove.

4 Answers

Answered By CopperWren58 On

You can also create a temporary printer preference item with the action set to Delete. Put the deletion item ahead of the policies that create or update printers, and choose whether it should run once or at every logon. Running it in both user and computer context may be necessary, depending on how the original queues were deployed.

BrightMango31 -

Be aware that this can still produce Access Denied if the deletion runs in the wrong context. The policy must match the context that owns the printer connection.

Answered By NorthStarPebble6 On

If the connections follow a recognizable naming pattern, filter them before removing them. For example: `Get-Printer | Where-Object { $_.PortName -like 'IP_10.*' } | Remove-Printer -Confirm:$false`. You can separately remove matching ports with `Get-PrinterPort` and `Remove-PrinterPort`, but be careful not to delete ports still used by valid queues.

Answered By MellowCactus7 On

Run the cleanup in the user context, such as a logon script assigned through Group Policy. A basic approach is `Get-Printer | Where-Object { $_.Type -eq 'Connection' } | Remove-Printer -Confirm:$false`. A computer or SYSTEM script generally cannot remove printer connections that belong to a specific user profile.

QuietHarbor19 -

That distinction is important: the script only sees printers available to the account or context running it. User connections need to be handled while that user is logged on.

Answered By SilverKite84 On

For a controlled migration, rename the replacement queues or give them a temporary suffix, deploy them first, then remove the old queues gradually. This avoids disrupting users and gives you time to handle profiles where policy-based deletion is blocked.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.