# Initialize an empty string to hold the PEM encoded certificates
$certContent = ""
Get-ChildItem Cert:\LocalMachine\Root |
Foreach-Object {
# Convert the certificate to Base64 and format it as PEM
$pem = "-----BEGIN CERTIFICATE-----`r`n" +
[System.Convert]::ToBase64String(
$_.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
),
[System.Base64FormattingOptions]::InsertLineBreaks) +
"`r`n-----END CERTIFICATE-----`r`n"
$certContent += $pem
}
# Write the PEM content to the output file
Set-Content -Path ca-certificates.pem -Value $certContent