Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export certificate from IIS using PowerShell

Tags:

powershell

iis

How do I export a self-signed certificate from IIS 7 using PowerShell?

like image 803
dhendry Avatar asked Dec 19 '11 15:12

dhendry


People also ask

How do I Export a pfx certificate from IIS?

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.


2 Answers

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
like image 200
Andrey Marchuk Avatar answered Oct 25 '22 19:10

Andrey Marchuk


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')) ) }
like image 24
Aaron Zollman Avatar answered Oct 25 '22 20:10

Aaron Zollman