Author Posts

May 18, 2018 at 3:52 pm

I'm attempting to create a ps script to import .pfx certificates into the CurrentUser store. The script will be executed at logon by about 30 individuals. Each user has a specific folder path where their certificate is stored, but the certificate names don't match their logon id. I'm trying to use a wild card in the -FilePath statement to locate the file, but I keep getting a message that the file can't be found; Import-PfxCertificate : The PFX file could not be found.
Is there a way (better way) to select a .pfx file using wild card notation? Thank you;

Code below:
$PlainTextPass = "xxxx"
$env:UserName
$pfxpass = $PlainTextPass |ConvertTo-SecureString -AsPlainText -Force
Import-PfxCertificate -FilePath C:\temp\$env\*.pfx cert:\CurrentUser\my -Password $pfxpass

May 18, 2018 at 4:13 pm

Something like this maybe?

$path = C:\temp\$env:username
get-childitem $path\*.pfx | Import-PfxCertificate -certstorelocation cert:\CurrentUser\my -Password $pfxpass

If you have multiple files you may need to do a foreach against it

May 18, 2018 at 10:59 pm

Hi Jon, thanks for the reply. I couldn't get your code to work but i was able to get the below to work. Where each user will have a folder with their logon id name and a .pfx cert also by their logon id.

$PlainTextPass = "xxxx"
$pfxpass = $PlainTextPass |ConvertTo-SecureString -AsPlainText -Force

$Path = "\\SomeUncName\Certs\$env:USERNAME\"
Import-PfxCertificate -FilePath $Path\$env:USERNAME.pfx cert:\CurrentUser\my -Password $pfxpass