Reputation: 698
I'm trying to convert a bunch of certificates to pfx format with a loop as there are many. The issue I'm running into is in regards to the private key. I am unsure of how to loop the right private key with the right cert. Below is my loop
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}
Upvotes: 0
Views: 816
Reputation: 25001
If the Basename
of the key and cert file matches, just do another replace:
$key = $_.FullName.ToString().Replace('.cer','.key')
Upvotes: 1