Saturday, March 16, 2013

Powershell - Ping servers using wmi class svr-ping.ps1

After a long time this is one new post from me... ;) !!!!
 
Here is one more PowerShell script which uses WMI class PingStatus to check if server is reachable or not remotely 

The computer/server name should be mentioned in "Computers.txt" file

The script can use both IP address or hostname to check the ping status remotely

Ofcourse there are many other ways to ping servers however this is the easiest way I found to be quick way to check the server ping status remotely


Content of svr-ping.ps1

------------------------------------------------------------------------------------
foreach ($computers in Get-Content "Computers.txt")
{

$Computer = Get-WmiObject Win32_PingStatus -f "Address='$computers'"

if($computer.StatusCode -eq 0) 
{
"{0,0} {1,5} {2,5}" -f$computer.Address, $computer.StatusCode, "Its pinging"
}
else
{
"{0,0} {1,5} {2,5}" -f $computer.Address, $computer.StatusCode, "Its not reachable"

}

------------------------------------------------------------------------------------

1 comment: