Monday, July 18, 2016

Ping a list of servers

Ever get tired of being given a list of servers to do something with and more than a handful are offline or have been retired?  I am, so I decided to write this quickie to validate which machines are online and which are not.  Depending on the number of servers in your list this process can take a few to complete.

The script below will return just the machines that responded.

$Computers = Get-Content C:\temp\Servers_Names.txt; Test-Connection $Computers -ErrorAction SilentlyContinue -Count 1 | Select-Object Address,IPv4Address,ResponseTime,BufferSize

This one will provide the results to a text file.

$Computers = Get-Content C:\temp\Servers_Names.txt; Test-Connection $Computers | Out-File C:\temp\Ping_Results.txt

And alternatively this script will just provide a count of how many can ping and how many can’t.


$computers = Get-Content C:\temp\Servers_Names.txt; $Computers | group {test-connection -count 1 -ComputerName $_ -quiet} | Sort-Object Name -Descending


Example:
  Count Name                    Group                                                                                                                                                                                                                            
  -----      ----                         -----                                                                                                                                                                                                                            
  14        True                      {Server1, Server2Server3Serve...}                                                                                                                                                                                    
  4          False                     {Server15Server16Server17, Se...                                                                                                                                                                 

No comments:

Post a Comment