And here’s the PowerShell: Pinging a computer script

PowerShell logo

The first thing you might notice is that the PowerShell version is a bit shorter. 3 lines of VBscript code, compared to 1 line of PowerShell script. That is, 1 line of code to do the actual ping.

And here is a short program which demonstrates how to use PowerShell to ping a computer:

$computer_name = "WISEFAQDC"

$address_string = "Address=" + "'" + $computer_name +"'"
$ping = Get-WmiObject -Class Win32_PingStatus -Filter $address_string
if ($ping.StatusCode -ne 0)
    {
    # the check -ne 0 means the ping check failed.
    Write-Host Server: $computer_name - Not pingable
    }
else
    {
    # the computer is visible on the network.
    Write-Host Server: $computer_name - is alive
    }

Bookmark and Share

Comments are closed.