# encoding: ascii
# api: powershell
# title: Ping-Host
# description: Simple function that pings a host and returns a boolean.
# version: 0.1
# type: function
# author: mafpc366
# license: CC0
# function: Ping-Host
# x-poshcode-id: 3829
# x-archived: 2012-12-23T07:29:32
# x-published: 2012-12-19T04:17:00
#
#
function Ping-Host {param( [string]$HostName,
[int32]$Requests = 3)
for ($i = 1; $i -le $Requests; $i++) {
$Result = Get-WmiObject -Class Win32_PingStatus -ComputerName . -Filter "Address='$HostName'"
Start-Sleep -Seconds 1
if ($Result.StatusCode -ne 0) {return $FALSE}
}
return $TRUE
}