question

mcse-4037 avatar image
0 Votes"
mcse-4037 asked BruceZhang-MSFT edited

iis - ssl certificate replace with powershell

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 !

windows-server-iis
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @mcse-4037 ,

but it does not work.

Is there any error message reported? If it cannot work, powershell will return some text with red color so that you can know what error is in the scripts.

I followed the scripts in this blog. It uses two commands to remove the binding of the old certificate and then add the binding of the new certificate, instead of performing two operations in one command. You'd better separate these two operations into two commands as well.

 Get-Item IIS:\SslBindings\10.238.82.89!443 | Remove-Item
    
 get-item -Path "cert:\LocalMachine\My\$certShop" | new-item -path IIS:\SslBindings\10.238.82.89!443




0 Votes 0 ·

1 Answer

mcse-4037 avatar image
0 Votes"
mcse-4037 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.