Use*_*ser 4 iis powershell iis-6 hostheaders powershell-1.0
在Windows Server 2003下使用Powershell 1.0和IIS 6.
我有大约200个网站,我想更改IP地址(如"网站标识"部分"IP地址"字段中"网站"选项卡上的网站属性中所列.
我找到了这段代码:
$site = [adsi]"IIS://localhost/w3svc/$siteid"
$site.ServerBindings.Insert($site.ServerBindings.Count, ":80:$hostheader")
$site.SetInfo()
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做但是:
Kev*_*Kev 10
以下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 "========================="
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3435 次 |
最近记录: |