Using Powershell to Convert PFX to PEM

ndr-itsolutions used Ask the Experts™

I'm looking for a code snippet to do the following, I've created a bit of the code:

1. Read a list certificates - $certs gci c:\certs -include *.pfx -name
2. For each certificate name run the following command against it
     openssl pkcs12 -in <certificate name.pfx> -out <certificate name.pem> -nodes -password pass:<Password>
3. The password has to be extracted from an excel spreadsheet with two columns, certificate name and password.

I essentially want to be able to convert a load of pfx certs to pem certs and retrieve the associated passwords from a spreadsheet, the certificate name in the spreadsheet will be identical to the one in step 1

Any help appreciated.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Does it really need to be an Excel file? A CSV is much easier to handle.


CSV is fine.
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
I'll reverse the logic slightly, using the CSV to locate files instead of going the other way round.
The CSV has columns certname (without file extension) and password.
push-location c:\certs
import-csv certs.csv | % { openssl pkcs12 -in "$($_.certname).pfx" -out "$($_.certname).pem" -nodes -password pass:$($_.password) }

Open in new window

This does not work well if you have a big list of certs, but only want to apply the script to a few you put the files in the folder.

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