Urgent help needed deleting local username with apostrophe

This topic contains 6 replies, has 4 voices, and was last updated by  James Bernie 2 months, 2 weeks ago.

  • Author
    Posts
  • #95248

    Gavin Steiner
    Participant

    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

  • #95250

    Don Jones
    Keymaster

    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?

    • #95296

      Gavin Steiner
      Participant

      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.

  • #95286

    Andy
    Participant

    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

    • #95293

      Gavin Steiner
      Participant

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

  • #95301

    Don Jones
    Keymaster

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

  • #95308

    James Bernie
    Participant

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

You must be logged in to reply to this topic.