Вот сценарий Powershell, который я недавно написал, который можно адаптировать для выполнения ваших задач:
# Updates IIS bindings across all sites by replacing all occurrences
# of $searchString for $replaceString in the binding host header.
# Note that the search and replace is case insensitive.
$searchString = "ovh-ws0"
$replaceString = "ovh-ws1"
foreach ($website in Get-Website) {
"Site: {0}" -f $website.name
$bindings = Get-WebBinding -Name $website.name
foreach ($binding in $website.bindings.Collection) {
$bindingInfo = $binding.bindingInformation
" Binding: {0}" -f $bindingInfo
if ($bindingInfo -imatch $searchString) {
$oldhost = $bindingInfo.Split(':')[-1]
$newhost = $oldhost -ireplace $searchString, $replaceString
" Updating host: {0} ---> {1}" -f $oldhost, $newhost
Set-WebBinding -Name $website.name -BindingInformation $bindingInfo -PropertyName "HostHeader" -Value $newhost
}
}
}
И это пример вывода из приведенного выше сценария:
Site: alpha
Binding: 100.101.102.103:80:alpha.redacted.com
Binding: 100.101.102.103:80:ovh-ws0-alpha.redacted.com
Updating host: ovh-ws0-alpha.redacted.com ---> ovh-ws1-alpha.redacted.com
Binding: 100.101.102.103:443:ovh-ws0-alpha.redacted.com
Updating host: ovh-ws0-alpha.redacted.com ---> ovh-ws1-alpha.redacted.com
Binding: 100.101.102.103:443:alpha.redacted.com
Site: beta
(etc)
Site: release
(etc)
Конечно, скрипт может быть адаптирован для изменения привязок другими способами.Например, следующий скрипт обновит IP-адреса:
# Updates IIS bindings across all sites by replacing all IP addresses from $oldIP to $newIP.
$oldIP = "100.101.102.103"
$newIP = "*"
foreach ($website in Get-Website) {
"Site: {0}" -f $website.name
$bindings = Get-WebBinding -Name $website.name
foreach ($binding in $website.bindings.Collection) {
$bindingInfo = $binding.bindingInformation
" Binding: {0}" -f $bindingInfo
if ($bindingInfo -imatch $oldIP) {
" Updating IP: {0} ---> {1}" -f $oldIP, $newIP
Set-WebBinding -Name $website.name -BindingInformation $bindingInfo -PropertyName "IPAddress" -Value $newIP
}
}
}