PowerShell

Ping Multiple Servers using “PowerShell”

 

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 🙂

Download script from this link : http://gallery.technet.microsoft.com/scriptcenter/Ping-Multiple-Servers-ba915a7c

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.

Ping

 

Download script from this link : http://gallery.technet.microsoft.com/scriptcenter/Ping-Multiple-Servers-ba915a7c

 

Thanks

aman dhally

6 thoughts on “Ping Multiple Servers using “PowerShell”

    1. Aman,
      Thank you for the script. I need some help modifying the script. I want the script to check a list of servers, and send one simple email that says everything is ok, I do not want it to list every server because the email is really long..Any Suggestions?
      Thanks,
      Jarrett

    2. HI jarrnett, you are welcome..and i glad that u like the script..

      humm..can u email me so that we can discuss this.. currently i am not sure how to do it, but i think this should be possible.

      thanks
      aman

Comments are closed.