如何使用PowerShell更新现有IIS 6网站
我试图创建一个PowerShell脚本,该脚本创建一个新的IIS 6网站并设置诸如App Pool,Wildcard应用程序映射,ASP.NET版本等内容.
I am trying to create a PowerShell script that creates a new IIS 6 web site and sets things like App Pool, Wildcard application maps, ASP.NET version, etc.
在Internet上进行了广泛搜索之后,我发现了一个脚本,该脚本可以让我创建一个新网站,而无需修改我需要的所有属性.
After extensive search on the Internet I found a script that allows me to create a new Web Site but not to modify all the properties I need.
$newWebsiteName = "WebSiteName"
$newWebsiteIpAddress = "192.168.1.100"
$newWebSiteDirPath = "c:\inetpub\wwwroot\WebSiteName"
$iisWebService = Get-WmiObject -namespace "root\MicrosoftIISv2"
-class "IIsWebService"
$bindingClass = [wmiclass]'root\MicrosoftIISv2:ServerBinding'
$bindings = $bindingClass.CreateInstance()
$bindings.IP = $newWebsiteIpAddress
$bindings.Port = "80"
$bindings.Hostname = ""
$result = $iisWebService.CreateNewSite
($newWebsiteName, $bindings, $newWebSiteDirPath)
非常感谢您提供有关如何扩展上述示例的帮助.
Any help on how to expand example above is greatly appreciated.
$ result对象包含新创建的IIsWebServer对象的路径.您可以通过执行以下操作访问虚拟目录,在该目录中可以配置更多属性:
The $result object contains the path to the newly created IIsWebServer object. You can get access to the virtual directory, where you can configure more properties, by doing the following:
$w3svcID = $result.ReturnValue -replace "IIsWebServer=", ""
$w3svcID = $w3svcID -replace "'", ""
$vdirName = $w3svcID + "/ROOT";
$vdir = gwmi -namespace "root\MicrosoftIISv2"
-class "IISWebVirtualDir"
-filter "Name = '$vdirName'";
# do stuff with $vdir
$vdir.Put();