iis - ssl certificate replace with powershell

mc se 1 Reputation point

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-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

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

    0 comments No comments

  2. Rahul Sonar 0 Reputation points

    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