Skip to content

Instantly share code, notes, and snippets.

@Bludwarf
Created August 2, 2023 10:00
Show Gist options
  • Save Bludwarf/17c99471011a11af9e6831ddc4b46cc4 to your computer and use it in GitHub Desktop.
Save Bludwarf/17c99471011a11af9e6831ddc4b46cc4 to your computer and use it in GitHub Desktop.
Powershell script to import certificates from a directory to a Java trust store file
$source_dir = "C:\certs"
$keystore = "C:\Java\truststore.jks"
$cert_extensions = @(
"*.cer",
"*.crt",
"*.der",
"*.pem"
)
$certs = @()
$cert_extensions | ForEach-Object {
$certs += Get-ChildItem $source_dir -Filter $_
}
$certs | Foreach-Object {
$cert = $_
Write-Output "Import du certificat $cert"
keytool -import -trustcacerts -alias $cert.BaseName -file $cert.FullName -keystore $keystore -keypass changeit -storepass changeit -noprompt
}
# Source : https://stackoverflow.com/a/20886446/1655155
Write-Host -NoNewLine 'Appuyer sur n''importe quelle touche pour fermer...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment