如何使用PowerShell更新现有IIS 6网站 [英] How to update existing IIS 6 Web Site using PowerShell

查看:230
本文介绍了如何使用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();

这篇关于如何使用PowerShell更新现有IIS 6网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆