Fail to use Import-PfxCertificate to install ssl certificate with error "invalid password", but manual install sucess

0

I am trying to install a ssl certificate by using Import-PfxCertificate on my Windows2012 server, this is my script:

$mypwd = ConvertTo-SecureString -String "$my!pa$$$word" -Force -AsPlainText
Import-PfxCertificate -FilePath D:\Downloads\my-cert.pfx Cert:\LocalMachine\My -Password $mypwd

After run it on my web server, following error reported:

Import-PfxCertificate : The specified network password is not correct. 0x80070056 (WIN32: 86 ERROR_INVALID_PASSWORD)
At C:\Users\Administrator\Desktop\smk-install-cert.ps1:5 char:1
+ Import-PfxCertificate -FilePath D:\Downloads\smk-qa.pfx Cert:\LocalMachine\My -P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Import-PfxCertificate], Exception
+ FullyQualifiedErrorId : System.Exception,Microsoft.CertificateServices.Commands.ImportPfxCertificate

However, I can install this certificate manually on this server successfully so I am sure the password is correct. I don't know what's wrong with this password, does any one has any idea or workaround on this problem?

ssl-certificate
windows-server-2012-r2
asked on Stack Overflow Nov 22, 2016 by Emma

1 Answer

0

I got it fixed, it indeed because of the password has special characters in it, I add escape character ` to each special character, the script worked and cert can be installed successfully.

answered on Stack Overflow Nov 23, 2016 by Emma

User contributions licensed under CC BY-SA 3.0