使用PowerShell从IIS导出证书
如何使用PowerShell从7导出自签名证书使用PowerShell从IIS导出证书,iis,powershell,Iis,Powershell,如何使用PowerShell从7导出自签名证书 dir cert:\localmachine\my | Where-Object { $_.hasPrivateKey } | Foreach-Object { [system.IO.file]::WriteAllBytes("c:\$($_.Subject).pfx", ($_.Export('PFX', 'secret')) ) } 资料来源: 这将把您的所有证书导出到C:\ 您可以通过运行以下命令来检查您拥有的证书: dir c
dir cert:\localmachine\my | Where-Object { $_.hasPrivateKey } | Foreach-Object { [system.IO.file]::WriteAllBytes("c:\$($_.Subject).pfx", ($_.Export('PFX', 'secret')) ) }
资料来源:
这将把您的所有证书导出到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-关于如何实现这一点有什么想法吗?发现以下内容将起作用-感谢您的帮助dir cert:\localmachine\my | Where Object{$\ hasprovatekey}Foreach Object{[system.IO.file]::writealbytes(“c:\shared\test\$($\ Subject.cer”,($\u.Export('CERT','secret'))我在尝试使用$\u.Subject时遇到“路径中的非法字符”错误,但$\u.Thumbprint有效。谢谢如何仅导出未过期的证书?