4

I want to be able to create a new website with a new host header (which I can obviously do using the IIS Manager) from the command line so that it can be scripted.

Essentially what you can do with iisweb on IIS 6.

2 Answers 2

6

Use built-in appcmd, like this - using the bindings argument a host header can be specified:

appcmd add site /name:contoso /id:2 /physicalPath:c:\contoso /bindings:http/*:80: marketing.contoso.com

The variable name string is the name, and the variable id uint is the unsigned integer that you want to assign to the site. The variables name string and id uint are the only variables that are required when you add a site in Appcmd.exe. The variable bindings string contains information that is used to access the site, and it should be in the form of protocol/IP_address:port:host_header.

2
  • 8
    One thing I found handy was adding multiple bindings in a single call. To do so, wrap each binding in quotes and comma-separate them: appcmd add site /name:contoso /bindings:"http/*:80:","https/*:443:" /physicalPath:C:\contoso. Otherwise, you have to do a separate call for each: appcmd set site /site.name:"G4" /+bindings.[protocol='https',bindingInformation='*:443:'].
    – patridge
    Jul 14, 2010 at 16:32
  • FYI its location is %windir%\system32\inetsrv\appcmd.exe
    – knocte
    Dec 6, 2016 at 9:22
0

Powershell:

Import-Module WebAdministration 
New-Website -name "[name]" -HostHeader "[www.example.com]" -PhysicalPath "[c:\inetpub\example.com\]"

Using Powershell combined with the .NET assembles:

[Microsoft.Web.Administration.ServerManager]::OpenRemote($WebServer)

You can basically control every facet of the web site/web server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .