2011-12-19 34 views

回答

8
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 
+0

谢谢,上面的代码工作正常,但我需要导出证书作为.cer而不是pfx - 关于如何实现这一点的任何想法? – dhendry 2011-12-19 16:06:37

+2

发现以下将工作 - 感谢您的帮助 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

3

值得关注的是,当我试图导出我的根证书,我不得不用指纹作为文件名,而不是主题,由于外商无效unicode中的语言字符。这个作品:

dir cert:\localmachine\root | 
Foreach-Object { [system.IO.file]::WriteAllBytes("c:\temp\$($_.Thumbprint).cer",  ($_.Export('CERT', 'secret'))) }