1

Today i was trying to search a method for "skip" the password when it is requested. Is there a way for do this or for do similar things, like put automatically a random password when requested?

Get-PfxCertificate "c:\path\file"

Thumbprint                                Subject
----------                                -------
****************************************  CN=****************
****************************************  CN=****************
Password: (example: random)

(I know that if you put a random password I will get an error but I do not care.)

  • [Here is a similar question answered](https://stackoverflow.com/questions/6239647/using-powershell-credentials-without-being-prompted-for-a-password) – KSingh Jan 10 '18 at 21:15

1 Answers1

1

You could attempt to load the certificate file without providing a password and suppress any exceptions thrown:

foreach($PfxFile in Get-ChildItem C:\Path\to\cert\files -Filter *.pfx) {
  try {
    [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromCertFile($PfxFile.FullName)
  }
  catch {
    continue
  }
}
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206