首页 > 解决方案 > Powershell:使用循环将证书转换为 pfx

问题描述

我正在尝试使用循环将一堆证书转换为 pfx 格式,因为有很多。我遇到的问题是关于私钥的。我不确定如何使用正确的证书循环正确的私钥。下面是我的循环

Get-ChildItem -Path $CertPath\SCP -Recurse -Include "*cer", "*.key" | 
ForEach-Object {
    $OutFile = $_.FullName.ToString().Replace(".cer",".pfx")
    $Password = Read-host "enter the password" -AsSecureString
    openssl pkcs12 -export -in $CertPath\Folder -inkey $PrivateKey -out $Outfile -password $Password}

标签: powershellloopscertificatepfx

解决方案


如果Basenamekey 和 cert 文件匹配,只需进行另一个替换:

$key = $_.FullName.ToString().Replace('.cer','.key')

推荐阅读