Skip to content

Instantly share code, notes, and snippets.

@dpo007
Created June 1, 2022 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpo007/1574a5c99f2fbba888b0abed329d5b5e to your computer and use it in GitHub Desktop.
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.
$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