如何在Powershell中将所有证书导出到文件

问题描述 投票:0回答:1

我正在尝试导出所有证书,但失败了。

我得到的最接近的解决方案是这个:

$mypwd = ConvertTo-SecureString -String "secret" -Force -AsPlainText
Get-ChildItem -Path Cert: -Recurse | where { $_.Thumbprint} | Export-PfxCertificate -Cert $_.Thumbprint -Password $mypwd -FilePath $_.Thumbprint.pfx

但是我收到错误

Export-PfxCertificate:Das Argument kann nicht an den 参数“Cert”gebunden werden,da es NULL ist。

这意味着$_为NULL,不能使用。我希望只是跳过失败的证书,但我没有导出任何单个文件。

powershell certificate
1个回答
0
投票

使用

ForEach-Object
将当前管道项绑定到
$_
:

Get-ChildItem -Path Cert: -Recurse | where { $_.Thumbprint} | ForEach-Object {
    Export-PfxCertificate -Cert $_.Thumbprint -Password $mypwd -FilePath "$($_.Thumbprint).pfx"
}
© www.soinside.com 2019 - 2024. All rights reserved.