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?
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.
User contributions licensed under CC BY-SA 3.0