Author Posts

March 6, 2018 at 3:45 pm

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

March 6, 2018 at 3:47 pm

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?

March 6, 2018 at 8:27 pm

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

March 7, 2018 at 3:15 am

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

March 7, 2018 at 3:18 am

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.

March 7, 2018 at 3:24 am

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

March 7, 2018 at 3:54 am

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\'