Created
June 1, 2022 17:57
-
-
Save dpo007/1574a5c99f2fbba888b0abed329d5b5e to your computer and use it in GitHub Desktop.
PowerShell :: Create a Self-Signed Certificate On Local Machine and Export it to PFX and CRT.
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
$subject = 'automationname.domain.ca' | |
$certFileName = $subject -replace '\.','_' | |
$certPass = ConvertTo-SecureString 'AutomationCertificate!1' -AsPlainText -Force | |
# Create a self-signed certificate in the local machine personal certificate store and store the result in the $cert variable. | |
$cert = New-SelfSignedCertificate -Subject $subject | |
# Display the new certificate properties | |
$cert | Format-List -Property * | |
# Save the certificate (with private key) into a PFX file, and just the public key into a CRT file. | |
[String] $certPath = Join-Path -Path 'cert:\LocalMachine\My\' -ChildPath $cert.Thumbprint | |
Export-PfxCertificate -Cert $certPath -FilePath ('{0}.pfx' -f $certFileName) -Password $certPass | |
Export-Certificate -Cert $certPath -FilePath ('{0}.crt' -f $certFileName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment