...
Sign in to the computer where the certificate was originally requested then start an administrative PowerShell session
Info Complete any remaining instructions in this PowerShell session unless directed otherwise
Modify then run the following commands to define the full path to certificate file:
$cert_file = 'C:\Content\certificate\host_domain_utexas_edu_cert.cer'Code Block Run the follow commands to select the certificate to be imported:
Code Block $path_cer = Read-Host -Prompt "Provide the path to the certificate file" $name_cer = Read-Host -Prompt "Provide the name of the certificate file"Run the follow commands toverify the certificate to be imported:
Code Block $file_cer = Get-ChildItem -Path $path_cer | Where-Object { $_.Name -Match $name_cer } | Sort-Object -Property LastWriteTime | Select-Object -Last 1 $test_cer = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($file_cer.FullName) $test_cer | Select-Object Thumbprint, HasPrivateKey, NotBefore, NotAfter, Subject, IssuerRun the following commands to import the certificate:
Code Block $cert_storefolder = 'Cert:\LocalMachine\My' $cert_object = Import-Certificate -CertStoreLocationFilePath $cert$file_storecer.FullName -FilePathCertStoreLocation $cert_filefolder
Run the following commands to replace the certificate:
Info The following commands will alert applications that an old certificate has been replaced by a new one. Only applications that subscribe to certificate notifications will be affected by these commands
Code Block $cert_match = Get-ChildItem -Path $cert_storefolder | Where-Object {$_.Subject -eq $cert_object.Subject -and $_.Issuer -eq $cert_object.Issuer } | Sort-Object -Property NotBefore -Descending If ($cert_match.Count -eq 2) { Try { Switch-Certificate -OldCert $cert_match[1] -NewCert $cert_match[0]; Remove-Item $cert_match[1] } Catch { Write-Host "Error replacing or removing certificate" } } If ($cert_match.Count -gt 2) { Write-Host "Too many matching certificate; reduce matching certificate count to 2" } }
...