See if this works (assuming there's only one web farm!):
(Get-IISConfigSection -SectionPath "webFarms").webfarms.webfarm|foreach{$_.server|select -expand address}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have been tasked with trying to automate the switching of the active/passive nodes within a Web Farm load-balancer in IIS 10. To this point, I have not been able to find a means that could be used to do this from a scripted perspective.
From exporting the current configuration of the server, there is a "webFarms" node that contains the information I need, and it is stored in the C:\Windows\System32\inetsrv\Config\ApplicationHost.config file.
<webFarms>
<webFarm name="rpm-lb" enabled="true">
<server address="server1" enabled="true">
<applicationRequestRouting hostName="server1" httpPort="8080" httpsPort="8443" />
</server>
<server address="server2" enabled="false">
<applicationRequestRouting hostName="server2" httpPort="8080" httpsPort="8443" />
</server>
<applicationRequestRouting>
<protocol httpVersion="PassThrough" timeout="00:02:00" reverseRewriteHostInResponseHeaders="true">
<cache enabled="false" />
</protocol>
</applicationRequestRouting>
</webFarm>
<applicationRequestRouting>
<hostAffinityProviderList>
<add name="Microsoft.Web.Arr.HostNameRoundRobin" />
</hostAffinityProviderList>
</applicationRequestRouting>
</webFarms>
If I pull information using PowerShell's Get-IISConfigSection commandlet, which results in this output:
PS C:\Windows\system32> Get-IISConfigSection -SectionPath "webFarms"
IsLocked : False
OverrideMode : Inherit
OverrideModeEffective : Deny
SectionPath : webFarms
Attributes : {onDemandHealthCheck}
ChildElements : {applicationRequestRouting}
ElementTagName : webFarms
IsLocallyStored : True
Methods :
RawAttributes : {[onDemandHealthCheck, False]}
Schema : Microsoft.Web.Administration.ConfigurationElementSchema
What I have been unable to find is how to get the server nodes from the configuration via PowerShell. If I can get that information, I think it would be fair to assume that I can update the active/passive nodes (enabled="true"/enabled="false").
If anyone can point me in the correct direction, or better yet, help me find the correct commands to execute, I'd be extremely appreciative.
Thanks!
Greg
See if this works (assuming there's only one web farm!):
(Get-IISConfigSection -SectionPath "webFarms").webfarms.webfarm|foreach{$_.server|select -expand address}
Hi,
Does this work? Sorry I've got no environment to test it.
Get-IISConfigSection -SectionPath "webFarms" | Get-IISConfigCollection -CollectionName "webFarm" | Get-IISConfigElement -ChildElementName "server"
Best Regards,
Ian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Since I have no servers, and no IIS, I'm assuming that the configuration file contains properly constructed XML. But, using your data sample (adding only a single tag at the beginning, I think that using XPATH is what you need if the IIS folks (who would be the subject matter experts for your question) can't help with the usage of that products cmdlets.
This just gets the 'server' nodes from within he webFarm node named 'rpm-lb' and swaps the active/passive state.
$t=@"
<?xml version="1.0" encoding="UTF-8"?>
<webFarms>
<webFarm name="rpm-lb" enabled="true">
<server address="server1" enabled="true">
<applicationRequestRouting hostName="server1" httpPort="8080" httpsPort="8443" />
</server>
<server address="server2" enabled="false">
<applicationRequestRouting hostName="server2" httpPort="8080" httpsPort="8443" />
</server>
<applicationRequestRouting>
<protocol httpVersion="PassThrough" timeout="00:02:00" reverseRewriteHostInResponseHeaders="true">
<cache enabled="false" />
</protocol>
</applicationRequestRouting>
</webFarm>
<applicationRequestRouting>
<hostAffinityProviderList>
<add name="Microsoft.Web.Arr.HostNameRoundRobin" />
</hostAffinityProviderList>
</applicationRequestRouting>
</webFarms>
"@
$xml=[xml]$t
$n = $xml.SelectNodes("//webFarm[@name = 'rpm-lb']/server")
$n | ForEach-Object{
"{0} is enabled? {1}" -f $_.address, $_.enabled
}
$n | ForEach-Object{
if ($_.enabled -eq "true") {$_.enabled = "false"}
elseif ($_.enabled -eq "false") {$_.enabled = "true"}
}
$xml.Save("c:\junk\NewFile.xml")