import-pfxcertificate -FilePath question

This topic contains 2 replies, has 2 voices, and was last updated by  SteveP 6 days, 14 hours ago.

  • Author
  • #100809


    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"
    $pfxpass = $PlainTextPass |ConvertTo-SecureString -AsPlainText -Force
    Import-PfxCertificate -FilePath C:\temp\$env\*.pfx cert:\CurrentUser\my -Password $pfxpass

  • #100818


    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

  • #100854


    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

You must be logged in to reply to this topic.