Hi,
Today I was looking for a little PowerShell script which can Ping multiple servers and give a consolidated view on PowerShell console that which one is Live and which one is Dead.
Then a decide to write my own and finally wrote it: ) and it is a only a 9 line script :)
You can copy and paste the script from below or you can download it from here : http://dl.dropbox.com/u/17858935/Ping_Multiple_Servers.zip
let me explain the script :
$Servername: is a variable which contain a list of comma separated Server name
in foreach script block we are selecting all servers in $ServerName variable and run Test-Connection cmdlets against them
in If Test-Connection evaluates that servers in Pinging that it writes “S$server is alive” otherwise it write “Server is dead”,
In test-connection Cmdlet we define that it should send only 2 Pings to the server using –count 2 switch parameter and used –Quiet Switch parameter so that is show the output in Boolean (true or false)
1: #### Provide the computer name in $computername variable
2:
3: $ServerName = "Dc-2","LocalHost","Server-2","Not-Exists","Fake-computer"
4:
5: ##### Script Starts Here ######
6:
7: foreach ($Server in $ServerName) {
8:
9: if (test-Connection -ComputerName $Server -Count 2 -Quiet ) {
10:
11: write-Host "$Server is alive and Pinging " -ForegroundColor Green
12:
13: } else
14:
15: { Write-Warning "$Server seems dead not pinging"
16:
17: }
18: }
19:
20: ########## end of script #######################
The output of the script will be like below link.
Download Link : http://dl.dropbox.com/u/17858935/Ping_Multiple_Servers.zip
Thanks
aman dhally