使用IIS 7.0 PowerShell创建web站点,Web应用,虚拟路径和应用程序池2011-12-06 博客园 代震军翻译介绍IIS PowerShell 名空间包括诸如: Web-Sites, Apps, Virtual Directories 和 Application Pools.使用内置的PowerShell cmdlets可以很容易创建一个名空间项和管理该项.创建Web站点如果您熟悉PowerShell 的话,就会知道在各种PowerShell 名空间下New-Item cmdlet 通常被用于创建新项。 举个例子,当前命令 "New-Item c:TestDirectory"会创建一个新的文件夹 (尽管多数人使用New-Item的别名命令"MD" 或 "MKDIR"). 在IIS 7.0 PowerShell 名空间下,New-Item 也常用于创建新的Web站点.参数在创建一个文件系统路径时,您需要指定一个路径名称. 不巧的是当前创建WEB站点时这是不够的. 除了像文件系统路径这样的参数之外,还需要network bindings. 下面的命令用于创建一个新的WEB站点并使用dir命令进行显示:
PS IIS:Sites> New-Item iis:SitesTestSite -bindings @{protocol="http";bindingInformation=":80:TestSite"} -physicalPath c:	est
PS IIS:Sites> dir
Name ID StatePhysical PathBindings
---- -- --------------------------
Default Web Site 1Startedf:inetpubwwwroot http *:80:
TestSite 2Startedc:	esthttp :80:TestSite这里直接使用了 -physicalPath 参数. 然而您可能会问: -bindings 看起来咋这么复杂?.在构造时通常使用hashtable (在 这里 了解更多PowerShell hash tables信息).hash table 中的键值对表示一个设置集合,该集合在IIS站点bindings section中会反射出相关属性:
<bindings>
<binding protocol="http" bindingInformation=":80:TestSite" />
</bindings>现在我们找出了一个使用hash table的原因: IIS 配置是可以使用属性进行扩展的。 (查看 这里了解更多信息). 您可以想像一下使用其它属性扩展 <binding> 元素节点. hash table 的键值对提供了这种弹性.坦白说,该语法有一点复杂. 我们正在考虑在Tech Preview中封装一些典型任务:比如创建站点的方法或脚本。