代码之家  ›  专栏  ›  技术社区  ›  caveman_dick

如何使用PowerShell将多个服务器绑定添加到iis6?

  •  0
  • caveman_dick  · 技术社区  · 17 年前

    我在尝试使用PowerShell将多个服务器绑定添加到单个网站时遇到了真正的问题!

    目前我有以下代码:

        function UpdateMetaBaseProperties($dirEntry, $Properties)
        {
            foreach($Prop in $Properties)
            {
                $KeyValue = $Prop.Split('=');       
                $dirEntry.psbase.Invoke("Put", ($KeyValue[0], $KeyValue[1]));
                $dirEntry.psbase.Invoke("SetInfo");     
                Write-Host "Setting property: $KeyValue";
            }
        }
    

    它适用于单值属性,但我似乎无法解决如何将其作为多值添加。

    我试过了

    1. 作为数组传递(引发异常)
    2. 作为逗号分隔字符串传递(将所有字符串放入1个主机条目中)
    3. 作为分号分隔字符串传递(将所有字符串放入1个主机条目)
    4. 运行两次Put(仅保存最后一个主机条目)

    我一直在谷歌上搜索,但似乎什么都没用!

    请帮助!!

    2 回复  |  直到 17 年前
        1
  •  2
  •   Nico    17 年前

    干得好:

    $site = [adsi]"IIS://localhost/w3svc/$siteid"
    $site.ServerBindings.Insert($site.ServerBindings.Count, ":80:$hostheader")
    $site.SetInfo()
    
        2
  •  0
  •   x0n    17 年前

    如果从www.iis.net安装IIS PowerShell提供程序,您将有一个更轻松的方法。( http://www.iis.net/1664/ItemPermalink.ashx )

    [E] PS> add-pssnapin webadministration
    [E] PS> new-webbinding -?
    
    NAME
        New-WebBinding
    
    SYNOPSIS
        Adds a new Web site binding to an existing Web site.
    
    
    SYNTAX
        New-WebBinding [[-Name] <String>] [-Protocol <String>] [-Port <UInt32>] [-IPAddress <String>] [-HostHeader <String>
        ] [-Force] [-WarningAction <ActionPreference>] [-WarningVariable <String>] [<CommonParameters>]
    
    
    DESCRIPTION
        Adds a new Web site binding to an existing Web site.
    
    
    RELATED LINKS
    
    REMARKS
        To see the examples, type: "get-help New-WebBinding -examples".
        For more information, type: "get-help New-WebBinding -detailed".
        For technical information, type: "get-help New-WebBinding -full".