ARR状态监控脚本
#####################################################################################
# THIS IS SAMPLE CODE AND IS ENTIRELY UNSUPPORTED. THIS CODE AND INFORMATION #
# IS PROVIDED "AS-IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, #
# INCLUDING BUT NOT LIMITED TO AN IMPLIED WARRANTY OF MERCHANTABILITY AND/OR #
# FITNESS FOR A PARTICULAR PURPOSE. #
#####################################################################################
# First add a reference to the MWA dll
$dll=[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
#Get the manager and config object
$mgr = new-object Microsoft.Web.Administration.ServerManager
$conf = $mgr.GetApplicationHostConfiguration()
#Get the webFarms section
$section = $conf.GetSection("webFarms")
$webFarms = $section.GetCollection()
foreach ($webFarm in $webFarms)
{
$Name= $webFarm.GetAttributeValue("name");
#Get the servers in the farm
$servers = $webFarm.GetCollection()
Write-Host "Farm Name: " $Name
foreach($server in $servers)
{
$ip= $server.GetAttributeValue("address")
#Get the ARR section
$arr = $server.GetChildElement("applicationRequestRouting")
$counters = $arr.GetChildElement("counters")
$isHealthy=$counters.GetAttributeValue("isHealthy")
$state= $counters.GetAttributeValue("state")
switch ($state)
{
0 {$state= "Available"}
1 {$state= "Drain"}
2 {$state= "Unavailable"}
default {$state= "Non determinato"}
}
if( $isHealthy)
{
$isHealthy="Healthy"
}
else
{
$isHealthy="Not Healthy"
}
Write-Host -NoNewLine $ip " " $state " " $isHealthy
#NEW LINE
Write-Host
}
#NEW LINE
Write-Host
}
Output shows all web farms installed on your server plus the status of each application server.
From:http://blogs.msdn.com/b/carmelop/archive/2013/04/29/how-to-monitor-application-request-routing-via-powershell.aspx