I have a series of machines in a cluster, each running IIS. I am working on a script that restarts services on those machines from a management box and as a preventive measure, I am trying to change the ARR rules to redirect any ongoing traffic that would go that machine to another one that is part of the cluster.
At the moment, I am using the script below to redirect the traffic, however, I have to run it from each machine in the cluster for it to work and do not know how to specify an IIS instance from the management box. Would you be able to help or show me an alternative on how to do this?
$computers = Get-ADComputer -Filter 'Name -like "ComputerID*"' | ForEach-Object {$_.Name}
ForEach ($computer in $computers) {
# Variables used in this section
$iisSite = "iis:sitesDefaultWebSite"
$filterRoot = "system.webServer/rewrite/rules/rule[@name='ReverseProxyInboundRule1$_']"
# Find the next server in the cluster
# New Clustered Servers is an array with all other servers that are part of the
# cluster, except for itself therefore, the first item will alway be another
# server in the cluster
$firstServer = $newClusteredServers[0]
# Get the hostname of the first server from the IP so it can be used in ARR
$firstServerName = ([system.net.dns]::getHostEntry($firstServer) | Select-Object HostName)[0].HostName.SubString(0,15)
# Find the hostnames of this server and next server in the cluster and store
# them as variables for future use and to reduce the overall size of the script
$arrOn = ([system.net.dns]::getHostEntry($firstServer) | Select-Object HostName)[0].HostName.SubString(0,15) # Set redirection
$arrOff = $computer # This will be the computer name when I am not redirecting traffic
# Sets ARR to the next server in the cluster
Write-Host "Setting ARR to $arrOn" -ForegroundColor Green
Set-WebConfigurationProperty -PSPath $iisSite -Filter "$filterRoot/action" -Name "URL" -Value "http://${arrOn}:3000/{R:1}"
######## Restart Script Goes Here #######
Set-WebConfigurationProperty -PSPath $iisSite -Filter "$filterRoot/action" -Name "URL" -Value "http://${arrOff}:3000/{R:1}"
}
question from:
https://stackoverflow.com/questions/65617519/modifying-arr-settings-over-remote-machines 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…