How to set hostname during SSL binding in IIS7

Recently I have talked to few customers who were looking for a way to add hostname on SSL binding. They were using IIS7 and unable to use the IIS Manager UI for it. In fact, IIS Manager "Add Site Binding" UI had the "Host name" field greyed out! Here is how to resolve it.

Note: You can set hostname using IIS7 manager while your binding type is "HTTP", but not when your binding type is "HTTPS".

The Solution: You need to use appcmd.exe that you can find under c:\windows\System32\inetsrv

appcmd set site /site.name: string  /+bindings.[protocol=' string ',bindingInformation=' string ']

The variable site.name string is name of the site to which you want to add a binding. The variable protocol string is the protocol that you want to use, and the variable bindingInformation string is the combination of IP address, port, and host header.

For example, to configure a site named contoso to have an HTTPS binding for all IP addresses, on port 443, without a host header, type the following at the command prompt, and then press ENTER:

appcmd set site /site.name: contoso  /+bindings.[protocol='https',bindingInformation='*:443:']