Created
June 7, 2023 08:21
-
-
Save Digiover/a2db4125efb069d62a8fedcd23212103 to your computer and use it in GitHub Desktop.
Import a PFX certificate into Windows Server and change its FriendlyName property in PowerShell
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
# Import a PFX certificate into Windows Server and change its | |
# FriendlyName property in PowerShell. | |
# | |
# Using Get-Credential here ensures the password doesn't get saved | |
# into PowerShell's history file. | |
# -- see https://www.saotn.org for more PowerShell goodness :) | |
# | |
$CommonName = "CHANGEME" | |
$CertFileName = "CHANGEME.pfx" | |
$mypwd = Get-Credential -UserName "${CommonName} SSL certificate" -Message 'Enter password below' | |
$params = @{ | |
FilePath = "\SSL-certs\${CommonName}\${CertFileName}" | |
CertStoreLocation = 'Cert:\LocalMachine\My' | |
Password = $mypwd.Password | |
} | |
$cert = Import-PfxCertificate @params | |
# Update the certificate FriendlyName with the CommonName string and | |
# year it expires | |
$cert.FriendlyName = "${CommonName} expires $((Get-Date).AddYears(1)).ToString("yyyy")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the last line (
$cert.FriendlyName = ...
) doesn't work, you can use:See https://www.saotn.org/install-ssl-tls-certificates-in-windows-server-using-powershell/ for more details.