Powershell to Get the list of Live Servers

Below Powershell script take list of servers as input and it pings the server, if servers replies then it will writes Live server name in C:\scripts\serversRunning.txt.

 $ServerList = Get-Content “C:\scripts\Serverlist.txt”
foreach($Server in $ServerList)
{
                 $Server
                $ping = New-Object System.Net.NetworkInformation.Ping
                $reply = $null
                $Server = $Server.trim()
                $reply = $ping.Send($Server)
                if ($reply.status -eq “Success”) {
                $out = $Server | out-File “C:\scripts\serversRunning.txt” -Append
                } else {
                        $Server | out-File “C:\scripts\serversnotpinging.txt” -Append
                }
 }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s