Marco Mazza
Marco Mazza

Reputation: 13

Powershell Script get-pfxcertificate skip password

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.)

Upvotes: 1

Views: 1289

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

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
  }
}

Upvotes: 1

Related Questions