使用PowerShell从IIS导出证书
答
dir cert:\localmachine\my | Where-Object { $_.hasPrivateKey } | Foreach-Object { [system.IO.file]::WriteAllBytes("c:\$($_.Subject).pfx", ($_.Export('PFX', 'secret'))) }
来源:Exporting Certificate With Private Key
这将您所有的证书导出到C:\
。
您可以通过运行检查你有什么证书:
dir cert:\localmachine\my
答
值得关注的是,当我试图导出我的根证书,我不得不用指纹作为文件名,而不是主题,由于外商无效unicode中的语言字符。这个作品:
dir cert:\localmachine\root |
Foreach-Object { [system.IO.file]::WriteAllBytes("c:\temp\$($_.Thumbprint).cer", ($_.Export('CERT', 'secret'))) }
谢谢,上面的代码工作正常,但我需要导出证书作为.cer而不是pfx - 关于如何实现这一点的任何想法? – dhendry 2011-12-19 16:06:37
发现以下将工作 - 感谢您的帮助 dir cert:\ localmachine \ my | Where-Object {$ _。hasPrivateKey} | Foreach-Object {[system.IO.file] :: WriteAllBytes(“c:\ shared \ test \ $($ _。Subject).cer”,($ _。Export('CERT','secret'))) } – dhendry 2011-12-19 16:17:52