Aléatoire WebRequest résultats avec PowerShell

J'ai le texte suivant extrait de code ci-dessous à partir de mon script c'est à l'aide d'un WebRequest de ping une liste de web/app serveurs et j'obtiens des résultats aléatoires en fonction de l'ordre du bon/mauvais serveurs sont répertoriés dans la liste de serveurs.

Par exemple, si les mauvais serveurs (où j'ai récupérer un code 404 ou 503) sont répertoriés en premier dans la liste, puis mon script semble rapport avec précision. Toutefois, si le bon serveur (ce qui revient un statut = "OK") est mentionné en premier, puis mes résultats sont inexactes.

Voici mon extrait de code:

$ServerList = gc "$pwd\servers\test_servers.lst"
ForEach ($_ in $ServerList)
{   
# Ping web server test
$url = "http://$_.domain.net/logon"
Write-Host "Pinging web address for server: $url ..."
$request = [System.Net.WebRequest]::Create($url)
$response = $request.GetResponse()
If ($response.StatusCode -eq "OK") 
{
    #$True
    Write-Host "Web Ping on $_ Succeeded."
} 
Else 
{
    #$False
    Write-Host "Web Ping on $_ FAILED!!!"
}       
}

Voici l'exemple de liste de serveur:

server1 (reports back a 404)
server2 (reports back a 503)
server3 (gets a status = "OK")

Et voici le "précis" cmd sortie lorsque je lance le script:

C:\TFS\Sandbox>powershell ./temp.ps1

Pinging web address for server: http://server1.domain.net/wfc/logon ...
Exception calling "GetResponse" with "0" argument(s): "The remote server return
ed an error: (404) Not Found."
At C:\TFS\Sandbox\temp.ps1:8 char:34
+     $response = $request.GetResponse <<<< ()
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Web Ping on server1 FAILED!!!

Pinging web address for server: http://server2.domain.net/wfc/logon ...
Exception calling "GetResponse" with "0" argument(s): "The remote server return
ed an error: (503) Server Unavailable."
At C:\TFS\Sandbox\temp.ps1:8 char:34
+     $response = $request.GetResponse <<<< ()
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Web Ping on server2 FAILED!!!

Pinging web address for server: http://server3.domain.net/wfc/logon ...
Web Ping on server3 Succeeded.

Maintenant, quand je re-commande de la liste de serveur où le serveur est répertorié en premier, comme suit:

server3 (gets a status = "OK")    
server1 (reports back a 404)
server2 (reports back a 503)

- Je obtenir des résultats inexacts où le serveur 1 et le serveur 2 sont arriver a signalé que OK:

Pinging web address for server: http://server3.domain.net/wfc/logon ...
Web Ping on server3 Succeeded.

Pinging web address for server: http://server1.domain.net/wfc/logon ...
Exception calling "GetResponse" with "0" argument(s): "The remote server return
ed an error: (404) Not Found."
At C:\TFS\Sandbox\temp.ps1:8 char:34
+     $response = $request.GetResponse <<<< ()
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Web Ping on server1 Succeeded.

Pinging web address for server: http://server2.domain.net/wfc/logon ...
Exception calling "GetResponse" with "0" argument(s): "The remote server return
ed an error: (503) Server Unavailable."
At C:\TFS\Sandbox\temp.ps1:8 char:34
+     $response = $request.GetResponse <<<< ()
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Web Ping on server2 Succeeded.

Pourquoi j'obtiens des résultats mitigés basé sur la façon dont les serveurs sont répertoriés?

Merci d'avance!

OriginalL'auteur Keith | 2012-02-01