2

I've looked through a ton of posts on here and across the web about special characters in Powershell, but no matter what I've tried so far my command continues to get caught up on special characters. I'm trying to generate a keytab with the command:

ktpass -out bosso.keytab -princ serviceAccount@DOMAIN.COM -pass "XX&XX"XX&" -kvno 255 -ptype KRB5_NT_PRINCIPAL -crypto AES256-SHA1

I've tried assigning the password to a variable, using the backtick to escape, double-quotes with escapes, single quotes. I'm at a loss for what else to try here.

T-Heron
  • 5,385
  • 7
  • 26
  • 52
  • 1
    How are you calling ktpass as its not a PowerShell command? Via a PS script? – henrycarteruk Nov 10 '17 at 17:09
  • 1
    It's not explicitly a powershell command, but it can be run in PS just as it can in cmd. If it's easier to escape the password issues in CMD, I'm all ears. I did attempt it there first. – Cameron Ezell Nov 10 '17 at 17:17
  • 3
    Are you using variables at all in this? If not and you have PS3.0+ then just use the stop parsing parameter. `ktpass --% -out....`. that is of course assuming cmd does not have any issues with it. Have you used outer single quotes for your inner double? `^` would be the escape character in cmd you could use – Matt Nov 10 '17 at 17:19
  • 1
    It would help if you were more clear what escaping you need (i.e. what errors you get) and what you mean by "I've tried using backtick". Because you have a double quoted string with a double quote in it, and the simple escape for that is a backtick `"XX\`"XX"` - so either you tried backtick but didn't try that, or that isn't the problem so my guessing without seeing an error isn't good enough. Or doubling it up with `"XX""XX"` For reference, `&` is not a special character in a powershell double quoted string. Mostly, only backtick, other quotes, and dollars are. – TessellatingHeckler Nov 10 '17 at 17:41
  • 1
    I wasn't aware of the stop parsing option in Powershell, but that did it! Thank you so much. – Cameron Ezell Nov 10 '17 at 17:43
  • @TessellatingHeckler - nice answer. You should turn it into an Answer to get credit for it. – T-Heron Nov 20 '17 at 12:54

1 Answers1

3

Thank you to Matt for the helpful comment! I was not aware of the stop parsing parameter, but using ktpass --% ... prevented Powershell from interpreting the quotation marks as part of the command.

  • You should "self-accept" your answer at this point since 2 days have passed. You'll get an extra 15 points for that. More importantly, this will also signpost the question as answered in Green helping out other Google searchers who may stumble upon this one in the future. – T-Heron Dec 05 '17 at 01:35