iis - ssl certificate replace with powershell

mc se 1 Reputation point
2022-04-13T08:41:38.34+00:00

Hello everybody.
I have this situation:
IIS with many sites with an SSL certificate associated with it (OLDcertificate.pfx)

I have this goal:
exchange the SSL certificate associated on multiple sites in IIS (with the new NEWcertificate.pfx)

I would kindly ask if anyone can help me locate the commands to do this task with powershell.

At the moment I am trying with these commands:

Get-WebBinding
Get-ChildItem -Path Cert: LocalMachine \ MY
$ OLDCertificateThumbprint = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$ NEWCertificateThumbprint = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
Get-WebBinding | Where-Object {$ _. CertificateHash -eq $ OLDCertificateThumbprint} | ForEach-Object {Write-Host "Working on" $ _ $ _. RemoveSslCertificate () $ _. AddSslCertificate ($ NEWCertificateThumbprint, 'My')}

but it does not work.

thanks !

Internet Information Services
{count} votes

2 answers

Sort by: Most helpful
  1. mc se 1 Reputation point
    2022-04-13T12:46:54.463+00:00

    NB: the NEWcertificate.pfx certificate has already been successfully imported into IIS

    0 comments No comments

  2. Rahul Sonar 0 Reputation points
    2023-10-02T03:44:19.3866667+00:00

    It replaces the certificate but all the other parameters like sslctlstorename, clientcertnegotiation goes away. How to keep all this existing information and only replcace the certificate

    0 comments No comments