如何使用脚本在IIS 7中添加新网站?

我希望能够通过命令行创build一个新的主机头(我明显可以使用IISpipe理器 )来创build一个新的网站,这样就可以编写脚本了。

基本上你可以用IIS 6上的iisweb做什么。

使用内置的appcmd ,像这样 – 使用绑定参数可以指定主机头:

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

variables名称string是名称,variablesid uint是要分配给站点的无符号整数。 variables名称string和id uint是在Appcmd.exe中添加站点时所需的唯一variables。 variables绑定string包含用于访问站点的信息,它应该是协议/ IP_address:port:host_header的forms。

Powershell :

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

使用Powershell与.NET组合:

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

基本上可以控制网站/ Web服务器的每个方面。