écrit un script powershell pour génlrer un certificat depuis une pki
- User
écrit un script powershell pour génlrer un certificat depuis une pki
- Assistant
Voici un exemple de script PowerShell qui utilise les cmdlets de certificats pour générer un certificat à partir d'une infrastructure à clés publiques (PKI).
# Spécifiez les chemins de fichiers pour les clés privées et les certificats $privateKeyFilePath = "C:\Chemin\vers\la\clé\privée.pfx" $certificateFilePath = "C:\Chemin\vers\le\certificat.cer" # Importez le module PKI Import-Module PKI # Définissez les paramètres pour la génération du certificat $certParams = @{ Subject = "CN=MonCertificat" CertStoreLocation = "Cert:\LocalMachine\My" Provider = "Microsoft Enhanced RSA and AES Cryptographic Provider" KeyExportPolicy = "Exportable" KeyLength = 2048 KeyAlgorithm = "RSA" NotAfter = (Get-Date).AddYears(1) } # Générez une nouvelle paire de clés privées et de certificat $cert = New-SelfSignedCertificate @certParams # Exportez la clé privée au format PFX Export-PfxCertificate -Cert $cert -FilePath $privateKeyFilePath -Password (Read-Host "Entrez un mot de passe pour la clé privée") # Exportez le certificat au format CER Export-Certificate -Cert $cert -FilePath $certificateFilePath # Affichez les informations du certificat généré $cert | Format-List # Fin du script