Created
November 7, 2023 21:25
-
-
Save akanieski/3eaa387dff49e648831b57f42b17c64d to your computer and use it in GitHub Desktop.
Export-WindowsCertStoreToPEM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get all certificates from the cert store | |
$certs = Get-ChildItem -Path "Cert:\CurrentUser\Root" | |
# Initialize an empty array to hold the PEM strings | |
$pemCerts = @() | |
# Loop over each certificate | |
foreach ($cert in $certs) { | |
# Export the certificate as a PEM string | |
$pem = [System.Convert]::ToBase64String($cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)) | |
# Add the PEM string to the array | |
$pemCerts += "# $($cert.Subject)" | |
$pemCerts += "-----BEGIN CERTIFICATE-----`n$pem`n-----END CERTIFICATE-----" | |
} | |
# Join the PEM strings into a single string | |
$pemFileContent = $pemCerts -join "`n" | |
# Write the PEM file | |
Set-Content -Path "certs.pem" -Value $pemFileContent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment