Urgent help needed deleting local username with apostrophe

Hi,

Someone ran a command to add a local user to 900 computers last week, and they pasted in an apostrophe at the end of the user name by mistake. It’s now:

UserName’

I can’t delete these using DOS or PowerShell because it’s coming back saying “The username doesn’t exist”. I’m guessing because the apostrophe is being seen as part of the command and not the username.

Can anyone help me with a PowerShell (or even DOS) command structure that I can use which will see the ’ as part of the username?

Thanks so much!

Gavin

HAHAHAHAHAHAHA.

Sorry. Couldn’t help it.

PowerShell shouldn’t have a problem so long as you delimit the entire username in double quotes. And the local SAM should be okay with it since apostrophes occur all the time in names.

What command are you trying? What error are you getting?

Would doing that to 900 computers in some Prod environments be a resume generating moment, I’d be worried unleashing that unless I had tested it a fair few times

Which is why I’m taking over. Not a very productive response but thanks for trying.

You’re right. What’s happening is they use Kaseya to run scripts across multiple customer networks, and since its acting as a middleman it’s goofing up the syntax thranslation somehow.

It normally handles PowerShell pretty well. In this case it’s barfing all over it.

Thanks for your reply though. It confirmed that I had the right idea. Appreciated.

Jeez I wish I had a Kaseya install to work with. I wonder if escaping the apostrophe would help?

Random thought, have you tried either setting the user name as a variable so the apostrophe might not cause so much of an issue? Or using a like query where you have everything but the apostrophe? Just thinking of ways you can achieve the same result without having to directly reference the apostrophe. Just because you know the actual account name doesn’t mean you have to directly reference it.

A quick test in PowerShell 5.1 I was able to create/query/remove the user account Test’ when using double quotes.

Good luck.

Additional random thought: no clue what Kaseya is but maybe you need to use regex for the account i.e. UserName'