How do I export a self-signed certificate from IIS 7 using PowerShell?
On the Export Private Key page, select Yes, export the private key, and then, click Next. On the Export File Format page, select Personal Information Exchange – PKCS #12 (. PFX) and then check Include all certificates in the certification path if possible.
dir cert:\localmachine\my | Where-Object { $_.hasPrivateKey } | Foreach-Object { [system.IO.file]::WriteAllBytes("c:\$($_.Subject).pfx", ($_.Export('PFX', 'secret')) ) }
Source: Exporting Certificate With Private Key
This will export all of your certificates into C:\
.
You can check what certificates you have by running:
dir cert:\localmachine\my
Worth noting that when I tried to export my root certificates, I had to use Thumbprint as the filename, not Subject, due to invalid foreign-language characters in the unicode. This works:
dir cert:\localmachine\root |
Foreach-Object { [system.IO.file]::WriteAllBytes("c:\temp\$($_.Thumbprint).cer", ($_.Export('CERT', 'secret')) ) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With