简体   繁体   English

如何使用PowerShell 1.0更改IIS6中所有站点的IP地址?

[英]How can I change the IP address of all sites in IIS6 using powershell 1.0?

Using Powershell 1.0 under Windows Server 2003 with IIS 6. 在Windows Server 2003下使用Powershell 1.0和IIS 6。

I have about 200 sites that I would like to change the IP address for (as listed in the website properties on the "website" tab in the "Web site identification" section "IP address" field. 我有大约200个网站,我想更改IP地址(如“网站标识”部分“IP地址”字段中“网站”选项卡上的网站属性中所列。

I found this code: 我找到了这段代码:

$site = [adsi]"IIS://localhost/w3svc/$siteid"
$site.ServerBindings.Insert($site.ServerBindings.Count, ":80:$hostheader")
$site.SetInfo()

How can I do something like this but: 我怎么能这样做但是:

  1. Loop through all the sites in IIS 遍历IIS中的所有站点
  2. Not insert a host header value, but change an existing one. 不插入主机标头值,但更改现有标头值。

The following PowerShell script should help: 以下PowerShell脚本应该有所帮助:

$oldIp = "172.16.3.214"
$newIp = "172.16.3.215"

# Get all objects at IIS://Localhost/W3SVC
$iisObjects = new-object `
    System.DirectoryServices.DirectoryEntry("IIS://Localhost/W3SVC")

foreach($site in $iisObjects.psbase.Children)
{
    # Is object a website?
    if($site.psbase.SchemaClassName -eq "IIsWebServer")
    {
        $siteID = $site.psbase.Name

        # Grab bindings and cast to array
        $bindings = [array]$site.psbase.Properties["ServerBindings"].Value

        $hasChanged = $false
        $c = 0

        foreach($binding in $bindings)
        {
            # Only change if IP address is one we're interested in
            if($binding.IndexOf($oldIp) -gt -1)
            {
                $newBinding = $binding.Replace($oldIp, $newIp)
                Write-Output "$siteID: $binding -> $newBinding"

                $bindings[$c] = $newBinding
                $hasChanged = $true
            }
            $c++
        }

        if($hasChanged)
        {
            # Only update if something changed
            $site.psbase.Properties["ServerBindings"].Value = $bindings

            # Comment out this line to simulate updates.
            $site.psbase.CommitChanges()

            Write-Output "Committed change for $siteID"
            Write-Output "========================="
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Powershell将多个ServerBindings添加到IIS6? - How can I add multiple ServerBindings to IIS6 using powershell? 我可以使用Powershell在远程IIS服务器上创建站点和应用程序池吗? - Can I create sites and application pools on a remote IIS server using Powershell? 如何在 IIS 到 PowerShell 中设置管理服务的 IP 地址限制? - How to set IP Address Restrictions for Management Service in IIS through PowerShell? IIS:在 PowerShell 中显示所有站点和绑定 - IIS: Display all sites and bindings in PowerShell 使用共享IP地址从IIS站点进行出站Web请求失败 - outbound web requests fail when made from IIS sites using shared IP address 如何使用Powershell脚本更改IIS-7的HTTP跟踪方法和.NET信任级别的配置? - How can I change the IIS-7 configuration for HTTP trace method and .NET trust level using a Powershell Script? 通过Powershell在IIS中进行IP地址和域限制 - IP address and domain restrictions in iis through powershell 如何在Gitlab中更改主机IP地址 - How can i change host IP address in Gitlab 如何在IIS服务器中将IP地址更改为主机名? - How to change IP address to host name in IIS server? IIS6窗口身份验证仅在通过DNS名称(而不是IP地址)访问站点时才起作用 - IIS6 windows authentication only working when site is accessed by DNS name (not IP address)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM