PowerShell command for PFX certificate with password not working, help!

zero000kool
zero000kool used Ask the Experts™
on
I am trying to install a certificate via powershell, and it keeps telling store does not exist.  Can someone advise what I am doing wrong.

 I have a xxx.pfx certificate with a password and I want to install it to the Trusted Publishers store on the local computer.
The certificate is for the machine

Import-PfxCertificate -FilePath c:\swsetup\xxxx20220426.pfx -StoreLocation LocalMachine -StoreName TrustedPublishers -Exportable -Password xyzxyz

Can someone help me with the correct PowerShell command.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
Try this.
$pass = Read-Host "Enter password" -AsSecureString
Import-PfxCertificate -FilePath "c:\swsetup\xxxx20220426.pfx" -CertStoreLocation "Cert:\LocalMachine\TrustedPublisher\" -Password $pass -Exportable

Open in new window

Author

Commented:
This works fine, but now how do I do this without asking for a password.
Not worried about security right now,  what is the command I need that I can specify a password.

Thanks
Top Expert 2014
Commented:
$pass = ConvertTo-SecureString "mypassword" -AsPlainText -Force

Open in new window

Author

Commented:
Thanks how can I insert a password without having to show it.  
The above "mypassword"  would be seen in the script.  
How can I run the script without showing the password.
Top Expert 2014

Commented:
You said you weren't concerned about security.  I've already given you two options, one that's secure and one that's not, so I'm not really sure what you're after.

You could put the password in a separate file and then read that in.
$pass = ConvertTo-SecureString (Get-Content "c:\temp\passwordfile.txt") -AsPlainText -Force

If you really are concerned with security after all, but don't want a prompt, then you can put the password in a file in an encrypted form.  I'll direct you to the help for the ConvertTo-SecureString parameter for more details -
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertto-securestring?view=powershell-5.1
Note that using this method, you will either have to either provide the value to the -Key parameter, or decryption of the file contents can only be done by using the same account on the same machine where the file contents were created.  For more questions on this I'll ask that you create a new question as it is a far different question than your original one of how to import a certificate.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial