Complex Password Breaking KeyTool command in PowerShell

43 Views Asked by At

I know this is something stupid, but hoping someone can point me in the right direction... I have a script to add a pfx file to a keystore. It searches a specific folder for a *.pfx file, then prompts for the password for the *.pfx file, then imports it into the keystore. The problem portion of my script is:

$pfxPwd = Read-Host "Enter password for PFX file"
keytool -importkeystore -srckeystore $pfxName -srcstoretype PKCS12 -srcstorepass $pfxPwd -destkeystore $keystore -srcalias $pfxAlias -destalias $serverFullNameValue -storepass $mypwd

This works fine most of the time, but if the password contains a specific character (I've narrowed it down to >, ', +, <, [, #, . or (, but not sure which - though you can probably see it immediately), it seems to break the command and lists out all the different switches that I can use with KeyTool. Is there something specific I should be doing with my $pfxPwd variable to ensure that it will accept the password, regardless of the characters that are in it?

0

There are 0 best solutions below