r/PowerShell • • 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.

0 Upvotes

8 comments sorted by

5

u/Dragennd1 1d ago

What does the error say when you try to remove it?

2

u/Schmatter_Raphiqui 1d ago

sounds like it's just throwing an invalid character error on the UNC path from what OP wrote, though piping Get-Printer directly shouldn't care about the name string

-6

u/workaccountandshit 1d ago

Couldn't find the printer, even though I'm piping the fucking object right into it. It's fucking up on the \ character it seems.

I'm now trying straight via the CIM object, that seems more promising

6

u/lan-shark 1d ago

If the issue is with the slashes, it might be where you typed the slashes. What happens if you just run Get-Printer? Do you see the printers you're looking for?

3

u/Dragennd1 1d ago

This is why I asked for the error and OP opted not to provide it. If OP was able to resolve the issue, his interpretation of the error would have fixed it already.

The actual command ran with the actual error output would help to resolve this very quickly.

1

u/lan-shark 1d ago

Yeah this guy wasted 15 minutes of Opus tokens before using his brain for 15 seconds....

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.