Skip to main content

Disappearing Certificate from IIS – Convert to PFX with PowerShell

31 January, 2024

Are you trying to add a .cer or a .crt file to IIS and it disappears? Did you add a PFX file and are getting a message that the password is incorrect? Use PowerShell in conjunction with Open SSL to do the conversion.

Download OpenSSL here. 

Command: & “$openssl” pkcs12 -export -certpbe PBE-SHA1-3DES -keypbe PBE-SHA1-3DES -nomac -out $pfxFilePath -inkey $keyFilePath -in $cerFilePath -passout pass:$password

 

PowerShell Script:

$cerFilePath = "C:\temp\www1.cer"
$keyFilePath = "C:\temp\private-key.key"
$password = "password"

$pfxFilePath = "C:\temp\output.pfx"

$openssl = "C:\ProgramFiles\OpenSSL-Win64\bin\openssl.exe"

# Combine the .cer and .key files into a .pfx using OpenSSL
& "$openssl" pkcs12 -export -certpbe PBE-SHA1-3DES -keypbe PBE-SHA1-3DES -nomac -out $pfxFilePath -inkey $keyFilePath -in $cerFilePath -passout pass:$password