Powershell - Update a certificate friendly name
Published: Powershell Estimated reading time: ~1 minutes
function Legacy-UpdateFriendlyName {
param(
[parameter(Mandatory = $true,
ValueFromPipeLine= $true)]
[string]$Name,
[parameter(Mandatory = $true)]
[string]$FriendlyName,
[ValidateSet("FindByThumbprint", "FindBySubjectName", "FindBySubjectDistinguishedName",
"FindByIssuerName", "FindByIssuerDistinguishedName", "FindBySerialNumber",
"FindByTimeValid", "FindByTimeNotYetValid", "FindByTimeExpired", "FindByTemplateName",
"FindByApplicationPolicy", "FindByCertificatePolicy", "FindByExtension",
"FindByKeyUsage", "FindBySubjectKeyIdentifier")]
[string]$Type = "FindByThumbprint"
)
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::MaxAllowed)
Try {
$certificates = $store.Certificates.Find($type,$name,$false)
if( -not([string]::IsNullOrEmpty($certificates)) ) {
foreach($cert in $certificates) {
$cert.FriendlyName = $FriendlyName # + " - " + $cert.Subject
#$cert
}
} else {
Write-Warning "No Certificates found"
}
} Catch {
$error[0]
}
$store.Close()
}