Oct 1, 2014 at 9:32 PM
Edited Oct 1, 2014 at 9:37 PM
I am attempting to create a script that exports a cert to a .cer file but it seems that
"Get-IssuedRequest -Property "RawCertificate"
is adding CR after the RawCertificate data.
I need help removing the CR or improving the process.
I am using the snippet below to get the RawCertificate and create a file.
I can build a .cer file that opens correctly but it is not seen as a valid cert on my load balancing device. Openssl commands used to verify the cert fail as well unless I remove the CR.
#get ALL certs created today and download to local folder
write-host "Copying Today's Approved Certs to C:\temp\ssl\upload\" -ForegroundColor Yellow
$approvedcerts = Get-CertificationAuthority -Name ca-i03 | Get-IssuedRequest -Property "RawCertificate" -Filter "NotBefore -ge $(Get-Date)"
foreach ($approvedcert in $approvedcerts)
$certexpyear = $approvedcert.NotAfter.Year
$filename = $approvedcert.CommonName
$filename = $filename -replace ".bcbsfl.com"
$filename = $filename + '_I_' +$certexpyear + '.cer'
New-Item c:\temp\ssl\upload\$filename -type file
Add-Content c:\temp\ssl\upload\$filename "-----BEGIN CERTIFICATE-----"
$approvedcert.RawCertificate | Add-Content c:\temp\ssl\upload\$filename
Add-Content c:\temp\ssl\upload\$filename "-----END CERTIFICATE-----"