2011-12-19 94 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'))) }