r/PowerShell • u/workaccountandshit • 1d ago
Question Mapped network printer via Add-Printer, can't remove it (what the hell)
We deployed printers via Intune as Powershell scripts (before the option was added to the Settings Catalog) and they've been chilling there for three years doing their job.
However, now that we're stepping away from Papercut, I have to remove these mapped printers but for the life of me, I can't get it done. I let Claude Opus at it for 15 minutes, couldn't get it done so what the fuck.
I've tried to:
- Get the printer with Get-Printer -name "printername" | remove-printer. The issue here is that Remove-Printer -name does not accept the "\" character but since it's a networked printer, it always starts with \\.
- Remove the registry keys that have the connection but that doesn't do shit.
- Ran this as standard user, elevated and SYSTEM. Nothing.
Am I missing something, here? We're Entra joined so no GPO's and I don't see a config profile to actually remove mapped printers.
UPDATE:
Alright, I found it. I forgot I was testing with Admin Protection in Intune at the same time. When Intune runs a Powershell script in the user context, it runs it under another context (ADMIN_myUserName). So of course it couldn't find shit. That's going to take a lot of rethinking.
5
u/Dragennd1 1d ago
What does the error say when you try to remove it?
3
u/Godcry55 1d ago
Is the Intune script being pushed to the endpoints or have you disabled it first?
Are you using “//“ ?
2
u/purplemonkeymad 1d ago
Removing from the registry will remove them, but you do need to remember to logout or reboot. Are these printers pushed by group policy? User or computer? If so you'll have to remove them from the policy before they can be removed manually.