Category Archives: IIS

How to use appcmd.exe to renew a new certificate for Bulk HTTPS URLs (Bindings)

While using multiple IIS server in a Load Balanced Environment, it will be a lot of work and challenge of changing/updating the certificate for large numbers of URLs bindings. In that type of scenario we can achieve simply by single line of command by using the appcmd.

Syntax

appcmd renew Binding /oldCert:oldcerthash /newCert:newcerthash

Execution STEPS

  1. Open old Certificate which need to replace with New installed certificate 
  2. Open Details Tab >> Go to Thumbprint >>Copy entire value and paste in notepad (see below image). Ensure removing the space in the Thumbprint
  3. Open New Certificate make a note of New Thumbprint and copy
  4. Open command prompt in administrator mode and Go to C:\windows\system32\inetsrv.
  5. Run below command

Ex : appcmd renew Binding /oldCert:‎f2a0d6168c1813158a850a098819704c369bb5da                        /newCert:‎B17v0d6168c1813158a850a098819704c369bb3dr

      

Exporting and Importing bulk website bindings in IIS

While using multiple IIS servers in a Load Balanced Environment, it will be a lot of work to create all your website twice with the same settings on each webserver.  In this scenario, it will create more critical to create a large number of binding for each server, so there is possible to export and import your configuration from one webserver to the other by using the command.

Executed and Tested Version

OS : Windows 10
IIS : 10.0.15063.0

To Export the website/IIS Bindings:

Macking backup of IIS configuration is as simple as copying the directory into a backup directory, so you don’t need anything special to do it.  Just execute the below command in the Command prompt to make the backup copy in “C” drive with the file name Import_ProdBindings.xml

%windir%\system32\inetsrv\appcmd list site /config /xml > C:\Import_ProdBindings.xml

To Import the website/IIS Bindings:

As like Backup, it very simple to add the config to the IIS by using below command.

%windir%\system32\inetsrv\appcmd add site /in < C:\Import_ProdBindings.xml

OUTPUT:

Error :

I had faced the below error while exporting the config to the IIS. This error is due to the presence of “Default Web Site” in the targeted IIS.  So you can delete the existing one before executing the new config OR you can change the name of “Default Web Site” in the config and start the import from backup.

Pretty easy, eh?  Except for the dirty little secret everyone knows…remembering to do a backup before starting the Import! 

“ERROR ( message:Failed to add duplicate collection element “Default Web Site”. )”